-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Sequence support for Apache Derby 10.6.1 in Hibernate 3.5.2
PostPosted: Mon May 31, 2010 12:01 pm 
Newbie

Joined: Mon May 31, 2010 11:50 am
Posts: 1
Hi,
Derby 10.6.1 officially supports sequences. (See JIRA-Task: https://issues.apache.org/jira/browse/DERBY-712, Docs: https://issues.apache.org/jira/browse/DERBY-4568).

I tried to use this feature with hibernate, but got this error:
Code:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: could not get next sequence value; nested exception is org.hibernate.exception.SQLGrammarException: could not get next sequence value
   org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:487)
   org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:430)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

root cause

org.springframework.dao.InvalidDataAccessResourceUsageException: could not get next sequence value; nested exception is org.hibernate.exception.SQLGrammarException: could not get next sequence value
   org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:613)
   org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
   org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:377)
   org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:632)
   dao.impl.HibernateScoreDaoImpl.saveScore(HibernateScoreDaoImpl.java:29)
   service.impl.ScoreServiceImpl.saveScore(ScoreServiceImpl.java:35)
   webapp.controller.GeckoHuntController.handleRequest(GeckoHuntController.java:59)
   org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
   org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:857)
   org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:792)
   org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:475)
   org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:430)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

root cause

org.hibernate.exception.SQLGrammarException: could not get next sequence value
   org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92)
   org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
   org.hibernate.id.SequenceGenerator.generateHolder(SequenceGenerator.java:132)
   org.hibernate.id.SequenceHiLoGenerator$1.getNextValue(SequenceHiLoGenerator.java:84)
   org.hibernate.id.enhanced.OptimizerFactory$LegacyHiLoAlgorithmOptimizer.generate(OptimizerFactory.java:351)
   org.hibernate.id.SequenceHiLoGenerator.generate(SequenceHiLoGenerator.java:81)
   org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:122)
   org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
   org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:56)
   org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
   org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:50)
   org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
   org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:705)
   org.hibernate.impl.SessionImpl.save(SessionImpl.java:693)
   org.hibernate.impl.SessionImpl.save(SessionImpl.java:689)
   org.springframework.orm.hibernate3.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:635)
   org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:372)
   org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:632)
   dao.impl.HibernateScoreDaoImpl.saveScore(HibernateScoreDaoImpl.java:29)
   service.impl.ScoreServiceImpl.saveScore(ScoreServiceImpl.java:35)
   webapp.controller.GeckoHuntController.handleRequest(GeckoHuntController.java:59)
   org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
   org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:857)
   org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:792)
   org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:475)
   org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:430)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

root cause

java.sql.SQLSyntaxErrorException: Syntaxfehler: Encountered "seq_score" at line 1, column 20.
   org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown Source)
   org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
   org.apache.derby.client.am.Connection.prepareStatement(Unknown Source)
   org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:534)
   org.hibernate.jdbc.AbstractBatcher.prepareSelectStatement(AbstractBatcher.java:145)
   org.hibernate.id.SequenceGenerator.generateHolder(SequenceGenerator.java:110)
   org.hibernate.id.SequenceHiLoGenerator$1.getNextValue(SequenceHiLoGenerator.java:84)
   org.hibernate.id.enhanced.OptimizerFactory$LegacyHiLoAlgorithmOptimizer.generate(OptimizerFactory.java:351)
   org.hibernate.id.SequenceHiLoGenerator.generate(SequenceHiLoGenerator.java:81)
   org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:122)
   org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
   org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:56)
   org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
   org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:50)
   org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
   org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:705)
   org.hibernate.impl.SessionImpl.save(SessionImpl.java:693)
   org.hibernate.impl.SessionImpl.save(SessionImpl.java:689)
   org.springframework.orm.hibernate3.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:635)
   org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:372)
   org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:632)
   dao.impl.HibernateScoreDaoImpl.saveScore(HibernateScoreDaoImpl.java:29)
   service.impl.ScoreServiceImpl.saveScore(ScoreServiceImpl.java:35)
   webapp.controller.GeckoHuntController.handleRequest(GeckoHuntController.java:59)
   org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
   org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:857)
   org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:792)
   org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:475)
   org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:430)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

root cause

org.apache.derby.client.am.SqlException: Syntaxfehler: Encountered "seq_score" at line 1, column 20.
   org.apache.derby.client.am.Statement.completeSqlca(Unknown Source)
   org.apache.derby.client.net.NetStatementReply.parsePrepareError(Unknown Source)
   org.apache.derby.client.net.NetStatementReply.parsePRPSQLSTTreply(Unknown Source)
   org.apache.derby.client.net.NetStatementReply.readPrepareDescribeOutput(Unknown Source)
   org.apache.derby.client.net.StatementReply.readPrepareDescribeOutput(Unknown Source)
   org.apache.derby.client.net.NetStatement.readPrepareDescribeOutput_(Unknown Source)
   org.apache.derby.client.am.Statement.readPrepareDescribeOutput(Unknown Source)
   org.apache.derby.client.am.PreparedStatement.readPrepareDescribeInputOutput(Unknown Source)
   org.apache.derby.client.am.PreparedStatement.flowPrepareDescribeInputOutput(Unknown Source)
   org.apache.derby.client.am.PreparedStatement.prepare(Unknown Source)
   org.apache.derby.client.am.Connection.prepareStatementX(Unknown Source)
   org.apache.derby.client.am.Connection.prepareStatement(Unknown Source)
   org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:534)
   org.hibernate.jdbc.AbstractBatcher.prepareSelectStatement(AbstractBatcher.java:145)
   org.hibernate.id.SequenceGenerator.generateHolder(SequenceGenerator.java:110)
   org.hibernate.id.SequenceHiLoGenerator$1.getNextValue(SequenceHiLoGenerator.java:84)
   org.hibernate.id.enhanced.OptimizerFactory$LegacyHiLoAlgorithmOptimizer.generate(OptimizerFactory.java:351)
   org.hibernate.id.SequenceHiLoGenerator.generate(SequenceHiLoGenerator.java:81)
   org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:122)
   org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
   org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:56)
   org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
   org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:50)
   org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
   org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:705)
   org.hibernate.impl.SessionImpl.save(SessionImpl.java:693)
   org.hibernate.impl.SessionImpl.save(SessionImpl.java:689)
   org.springframework.orm.hibernate3.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:635)
   org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:372)
   org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:632)
   dao.impl.HibernateScoreDaoImpl.saveScore(HibernateScoreDaoImpl.java:29)
   service.impl.ScoreServiceImpl.saveScore(ScoreServiceImpl.java:35)
   webapp.controller.GeckoHuntController.handleRequest(GeckoHuntController.java:59)
   org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
   org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:857)
   org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:792)
   org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:475)
   org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:430)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


Solution is (imho):
org.hibernate.dialect.DerbyDialect needs to implement getSequenceNextValString as follows
Code:
   public String getSequenceNextValString(String sequenceName) {
      return "values next value for " + sequenceName;
   }

instead of
Code:
   public String getSequenceNextValString(String sequenceName) {
      return "values nextval for " + sequenceName;
   }


Am I right? (My sample app worked fine after modifying field "sql" in "SequenceGenerator")
If yes, how to add this code officially to hibernate?

Maybe, there is more to do than only this change!? Is there already progress on this topic?

Greets from Germany, Sebastian


Top
 Profile  
 
 Post subject: Re: Sequence support for Apache Derby 10.6.1 in Hibernate 3.5.2
PostPosted: Sat Jul 03, 2010 4:13 pm 
Newbie

Joined: Sat Jul 03, 2010 4:07 pm
Posts: 1
I'm runing Derby 10.6.1 with Hibernate 3.5.3-Final and I'm get this error:

FINE: values nextval for UserLogSequence
WARNING: SQL Error: -1, SQLState: 42X01
SEVERE: Sintax error: Encountered "UserLogSequence" at line 1, column 20.
WARNING: A system exception occurred during an invocation on EJB UserLogBean


Top
 Profile  
 
 Post subject: Re: Sequence support for Apache Derby 10.6.1 in Hibernate 3.5.2
PostPosted: Mon Jul 05, 2010 3:26 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Quote:
Am I right? (My sample app worked fine after modifying field "sql" in "SequenceGenerator")
If yes, how to add this code officially to hibernate?

Maybe, there is more to do than only this change!? Is there already progress on this topic?

Please check on JIRA that there isn't a duplicate, and then open a new issue.
If you attach your code as a patch it's likely to get pulled in quickly.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Sequence support for Apache Derby 10.6.1 in Hibernate 3.5.2
PostPosted: Fri Jul 30, 2010 9:42 am 
Newbie

Joined: Thu Dec 01, 2005 11:48 pm
Posts: 8
filed report under http://opensource.atlassian.com/project ... e/HHH-5427 after confirming problem and fix. thx for the information!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.