-->
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.  [ 1 post ] 
Author Message
 Post subject: Failure to save object which contains a collection of compon
PostPosted: Fri Mar 20, 2009 4:56 am 
Newbie

Joined: Fri Mar 20, 2009 4:37 am
Posts: 6
Hi

I'm using Spring 2.5 + Hibernate JPA. I have a class which contains a collection of components. Whenever I try to save an object of that class, I get the error: could not get or update the next value.

Here is the code:

Code:
@Entity
public class Vendor implements Serializable {
  @Id
  @GeneratedValue(strategy=GenerationType.AUTO)
  private Long id; 
  // a bunch of other fields

  @CollectionOfElements
  @JoinTable(
    name = "SUPPLIED_ITEMS",
    joinColumns = @JoinColumn(name = "VENDOR_ID")
  )
  @CollectionId(
    columns=@Column(name="SUPPLIED_ITEM_ID"),
    type=@Type(type="long"),
    generator="sequence"
  )
  private Collection<VendorSuppliedItem> suppliedItems = new ArrayList<VendorSuppliedItem>();

  // a bunch of getters and setters
}


the VendorSuppliedItem class

Code:
@Embeddable
public class VendorSuppliedItem implements Serializable {
  private String suppliesNo;
  private String suppliesName;
  private String unit;
  private BigDecimal price;
  private int minimumOrder;
  private int lead;
  private float discount;
  private String remark;

  // a bunch of getters and setters
}


and the stack trace

Code:
could not get or update next value; nested exception is org.hibernate.exception.SQLGrammarException: could not get or update next value
org.springframework.dao.InvalidDataAccessResourceUsageException: could not get or update next value; nested exception is org.hibernate.exception.SQLGrammarException: could not get or update next value
        at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:613)
        at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:95)
        at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:306)
        at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:62)
        at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:212)
        at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:146)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
        at $Proxy50.save(Unknown Source)
        at com.tikionline.logos.dao.VendorDaoTest.testSave(VendorDaoTest.java:90)
        at org.springframework.test.context.junit4.SpringTestMethod.invoke(SpringTestMethod.java:163)
        at org.springframework.test.context.junit4.SpringMethodRoadie.runTestMethod(SpringMethodRoadie.java:233)
        at org.springframework.test.context.junit4.SpringMethodRoadie$RunBeforesThenTestThenAfters.run(SpringMethodRoadie.java:333)
        at org.springframework.test.context.junit4.SpringMethodRoadie.runWithRepetitions(SpringMethodRoadie.java:217)
        at org.springframework.test.context.junit4.SpringMethodRoadie.runTest(SpringMethodRoadie.java:197)
        at org.springframework.test.context.junit4.SpringMethodRoadie.run(SpringMethodRoadie.java:143)
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:142)
Caused by: org.hibernate.exception.SQLGrammarException: could not get or update next value
        at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
        at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
        at org.hibernate.engine.TransactionHelper$1Work.doWork(TransactionHelper.java:41)
        at org.hibernate.engine.transaction.Isolater$JdbcDelegate.delegateWork(Isolater.java:187)
        at org.hibernate.engine.transaction.Isolater.doIsolatedWork(Isolater.java:43)
        at org.hibernate.engine.TransactionHelper.doWorkInNewTransaction(TransactionHelper.java:51)
        at org.hibernate.id.TableGenerator.generate(TableGenerator.java:94)
        at org.hibernate.id.TableHiLoGenerator.generate(TableHiLoGenerator.java:62)
        at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:99)
        at org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:49)
        at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:131)
        at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:87)
        at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:38)
        at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:618)
        at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:592)
        at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:596)
        at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:220)
        at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:193)
        at $Proxy41.persist(Unknown Source)
        at com.tikionline.logos.dao.VendorDaoImpl.save(VendorDaoImpl.java:38)
        at com.tikionline.logos.dao.VendorDaoImpl.save(VendorDaoImpl.java:19)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:301)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
        at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:138)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'read only with rs' at line 1
        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
        at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
        at com.mysql.jdbc.Util.getInstance(Util.java:381)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542)
        at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1734)
        at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1885)
        at org.hibernate.id.TableGenerator.doWorkInCurrentTransaction(TableGenerator.java:134)
        at org.hibernate.engine.TransactionHelper$1Work.doWork(TransactionHelper.java:38)


Any help is much appreciated

Thanks

Saito


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

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.