This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JPA/Hibernate: @GeneratedValue doesnt work

Martin Dames
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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(
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(
at birthday.dao.jpa.JpaDAO.persist(
at birthday.dao.jpa.JpaDAO.persist(
at birthday.test.TestDAO.main(

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!

It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic