Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JPA 1.0 - How to override @TableGenerator in subclass

 
Vincenzo Turco
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi developers,
I am facing a problem I have found no solution to yet surfing the web.
Any help would be appreciated.
It's about JPA 1.0 persistence and how pKey generation is handled when class hierarchies and mappedsuperclasses are involved.

My Base Class is like:


However I found out that defining the @Id on the base class leads to all persistent subclasses sharing the same row in the tableGenerator and thus the same counter.
I would like to have separate tableGenerator rows (i.e. counters) for the generation of pKeys in each subclass
How can this behavior be achieved?

Thanks, regards
Vincenzo
 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you remove the @TableGenerator, then it may default to a different sequence/row for each subclass (but you will need to use the default table name).

Otherwise, you could try overriding the mapping for the entire id in each subclass (or even only map the id in each subclass).

Or just accept having a single sequence for all subclasses, which may be best.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic