[hibernate-users] postgres @GeneratedValue
Christine Karman
mylists at christine.nl
Thu Apr 29 04:19:18 EDT 2010
We're having an issue with generated primary keys in a postgres
database. We use Seam, JbossAS, JPA, Hibernate. In a class named Address
we have a "long id" with the following annotations:
@Id
@SequenceGenerator(name = "ADDRESS_SEQ", sequenceName =
"address_id_seq", allocationSize = 1, initialValue =51)
@GeneratedValue(generator = "ADDRESS_SEQ")
private long id;
This works perfectly well, until we decided to seed the database with an
import script. It seems like Hibernate does not see the imported
addresses. The address class in Postgres has a field 'id' of type
"BigInt". But in order to have autogenerated keys, it should be 'serial'.
Our solution was to change the annotations to
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
Now, I'm happy that we found a solution, but I don't understand why this
works. Also, shouldn't Hibernate always make @GeneratedValue fields of
type 'serial'?
From what I found googling, this seems to be a problem that only occurs
when you use Postgres.
dagdag
Christine
--
*BiD **Network*
Preparing emerging market entrepreneurs for investors
www.bidnetwork.org <http://www.bidnetwork.org/>
*Come to the SME investor marketplace on June 2nd**
--> smeforum2010.org <http://smeforum2010.org/>*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/hibernate-users/attachments/20100429/27e818d0/attachment-0001.html
More information about the hibernate-users
mailing list