File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes JPA/Hibernate: @GeneratedValue doesnt work Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "JPA/Hibernate: @GeneratedValue doesnt work" Watch "JPA/Hibernate: @GeneratedValue doesnt work" New topic
Author

JPA/Hibernate: @GeneratedValue doesnt work

Martin Dames
Greenhorn

Joined: Aug 29, 2009
Posts: 3
Hi,

Im running into a simple issue and can not find the solution?!

I have an entity object with a technical id as primary key "BaseEntity" (its actual a superclass entity which provides the technical key for each sub-entity. Im using a Generic DAO pattern.



My Testcode looks like:


So, Person extends the BaseEntity above.

The persist() method throws the following exception:


Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: could not insert: [birthday.entities.Person]
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:614)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:226)
at birthday.dao.jpa.JpaDAO.persist(JpaDAO.java:40)
at birthday.dao.jpa.JpaDAO.persist(JpaDAO.java:1)
at birthday.test.TestDAO.main(TestDAO.java:38)

...
Caused by: java.sql.SQLIntegrityConstraintViolationException: Column 'OBJECTID' cannot accept a NULL value.
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source)


So, this should not happen since the id has to be generated through hibernate/Derby.... since I used the @ID @GeneratedValue combination at the BaseEntity.

With EclipseLink as JPA Provider this works very well.... has anyone an idea what the problem is?

Thank you guys!

persistence.xml:
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JPA/Hibernate: @GeneratedValue doesnt work
 
Similar Threads
Double insertion using entity lifecycle listener
javax.persistence.PersistenceException
JPA: Unable to configure EntityManagerFactory
org. postgresql. util. PSQLException: ERROR: relation does not exist
java.lang.IllegalArgumentException: Unknown entity