Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Hibernate 4 Id generation  RSS feed

 
Himanshu Mishra
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am using hibernate 4 as JPA provider, the database used is sql server 2005. I was trying to create a new records in a table using JPA. The table does not have an identity column but there is a primary key column. With Hibernate 3, I am able to create the records but not with hibernate 4. It gives me error like "Hibernate_sequence" does not exists.

I have tried "Identity" and "Auto". With hibernate 3, I dont have to specify any generator.

The error is " could not read a hi value: java.sql.SQLException: Invalid object name 'hibernate_sequence'"

Thanks,
Himanshu
 
Roel De Nijs
Marshal
Posts: 11006
161
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this one could be helpful.
 
Himanshu Mishra
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks you..

That helps....
 
Roel De Nijs
Marshal
Posts: 11006
161
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad I could help!

Nice to know: instead of making a "thank you" post, you could also the post(s) which you liked. It's easier, faster and other ranchers will see immediately which are the "starred" posts.
 
Alps Chauhan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am facing same issues while upgrading hibernate version to  5.0. Hibernate is using SequenceStyleGenerator and giving error-

ERROR org.hibernate.id.enhanced.TableStructure - could not read a hi value
com.microsoft.sqlserver.jdbc.SQLServerException: Invalid object name 'hibernate_sequence'.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:216)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1515)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:404)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:350)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:5696)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1715)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:180)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:155)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeQuery(SQLServerPreparedStatement.java:285)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:353)
at org.hibernate.id.enhanced.TableStructure.executeQuery(TableStructure.java:224)
at org.hibernate.id.enhanced.TableStructure.access$300(TableStructure.java:46)
at org.hibernate.id.enhanced.TableStructure$1$1.execute(TableStructure.java:139)
at org.hibernate.id.enhanced.TableStructure$1$1.execute(TableStructure.java:126)
at org.hibernate.jdbc.WorkExecutor.executeReturningWork(WorkExecutor.java:55)
at org.hibernate.jdbc.AbstractReturningWork.accept(AbstractReturningWork.java:34)
at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcIsolationDelegate.delegateWork(JdbcIsolationDelegate.java:56)
at org.hibernate.id.enhanced.TableStructure$1.getNextValue(TableStructure.java:125)
at org.hibernate.id.enhanced.NoopOptimizer.generate(NoopOptimizer.java:40)
at org.hibernate.id.enhanced.SequenceStyleGenerator.generate(SequenceStyleGenerator.java:412)
at org.hibernate.collection.internal.PersistentIdentifierBag.preInsert(PersistentIdentifierBag.java:375)
at org.hibernate.persister.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:1264)
at org.hibernate.action.internal.CollectionRecreateAction.execute(CollectionRecreateAction.java:50)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:560)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:434)
at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:337)
at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:39)
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1282).

..


We are not using annotations. Current version is 3.6. I migrated to 4.3 and faced no issues. Using SQLServer2012. Setting my configurations in the code like this -
...
...
c.setProperty("hibernate.dialect", SQLServer2012Dialect.class.getName());
c.setProperty("hibernate.id.new_generator_mappings", "false");

c.configure("hibernate.cfg.xml"); //hibernate.cfg.xml has all mapping resources

this.sessionFactory = c.buildSessionFactory();

I did not have to set hibernate.id.new_generator_mappings to false for version 4.3. But with hibernate version 5.0.9 this setting is not working. When I debugged, hibernate is using SequenceGenerator for older versions but it is using SequenceStyleGenerator for 5.0.9. Can you please advise.

I am using SEQUENCE.

Thanks


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