Forums Register Login

JPA/Hibernate Generator issues...

+Pie Number of slices to send: Send
I'm using JPA Annotations with Hibernate backed by a PostGreSQL database. I've been generally quite happy with how cleanly everything works, but I've had a few complaints over how @GeneratedValue interacts with the rest of the system.

Currently I have to do something like:

Now I know I can configure a NamingStrategy to handling Competition<->competitions mapping and I'm not concerned about that. However the verboseness of making a GeneratedValue read from a normally named PostGreSQL sequence is annoying.

I would rather be able to use only @GeneratedValue, ie the "Native" generator type, which would resolve back to a sequence under PostGreSQL. Unfortunately it defaults to a single, shared-across the entire database, sequence, not a per table sequence. Thus I need to provide explicitly for a) the name of the sequence via a @SequenceGenerator and
b) for the entity to use a generator...

I'm not too happy with this from a portability stand-point (but I don't anticipate leaving PostGreSQL) and I'm not happy with the wordiness.

There's no place in a NamingStrategy, that I could find at least, for providing to override the sequence name used by Native.

Has anyone else run across this? Is there a good solution?

(If I could get hbm2ddl to work, perhaps I wouldn't care as much, but at present I'm tending to create the database first and definitely like being able to use PostGreSQL "serial" type for now....)
rubbery bacon. rubbery tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 3463 times.
Similar Threads
Orphan delete doesn't seem to be working properly
JPA impl. w/Hibernate & Oracle PK Sequences/Triggers
Getting stuck with persisting a M:M relationship
Schema generated via Hibernate, sequence issue?
Entity with id 0
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 04:33:52.