javax.persistence.RollbackException: Error while committing the transaction

Hibernate JIRA | Karsten Wutzke | 6 years ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    JPA/Hibernate: java.sql.SQLException: Invalid argument in JDBC call: parameter index out of range

    Stack Overflow | 6 years ago | Kawu
    javax.persistence.RollbackException: Error while committing the transaction
  2. 0

    The following mappings are all JPA 1.0 compatible (no derived identifiers): {code:Company.java} @Entity @Table(name = "Companies") public class Company { @Id @Column private Integer id; @Column private String name; ... } {code} {code:PQ.java} @Entity @Table(name = "PQs") public class PQ implements Serializable { @Id @Column private Integer id; @Column private String name; ... } {code} {code:Partnership.java} @Entity @Table(name = "Partnerships") @IdClass(value = PartnershipId.class) public class Partnership implements Serializable { @Id @Column(name = "pq_id", insertable = false, updatable = false) private Integer pqId; @Id @Column(name = "company_id", insertable = false, updatable = false) private Integer companyId; @Column(name = "ordinal_nbr") private Integer ordinalNbr; @ManyToOne @JoinColumn(name = "pq_id", referencedColumnName = "id") private PQ pq; @ManyToOne @JoinColumn(name = "company_id", referencedColumnName = "id") private Company company; ... } {code} {code:PartnershipId.java} public class PartnershipId implements Serializable { private Integer pqId; private Integer companyId; public PartnershipId() { } public PartnershipId(Integer pqId, Integer companyId) { this.pqId = pqId; this.companyId = companyId; } ... } {code} Note, the insertable = false, updatable = false on @JoinColumn relationships. Running the following test code {code:Main.java} public class Main { private static String PERSISTENCE_UNIT_NAME = "standalonePu"; private static EntityManagerFactory emf; private static EntityManager em; private static EntityTransaction trans; public static void main(String[] args) { setUp(PERSISTENCE_UNIT_NAME); trans.begin(); PQ detachedPq = new PQ(1, "Test PQ"); Company detachedCompany = new Company(1, "Test Company"); PQ pq = em.merge(detachedPq); Company company = em.merge(detachedCompany); Partnership detachedPartnership = new Partnership(1, 1, 1); detachedPartnership.setPQ(pq); detachedPartnership.setCompany(company); Partnership partnership = em.merge(detachedPartnership); partnership = em.find(Partnership.class, new PartnershipId(1, 1)); System.out.println("Persistent partnership = (" + partnership.getPQId() + ", " + partnership.getCompanyId() + ", " + partnership.getOrdinalNbr() + ")"); trans.commit(); close(); } private static void setUp(String puName) { emf = Persistence.createEntityManagerFactory(puName); em = emf.createEntityManager(); trans = em.getTransaction(); } private static void close() { em.close(); emf.close(); } } {code} fails with a really strange exception: ERROR: Invalid argument in JDBC call: parameter index out of range: 4 Exception in thread "main" javax.persistence.RollbackException: Error while committing the transaction at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:90) at main.Main.main(Main.java:44) Caused by: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Invalid argument in JDBC call: parameter index out of range: 4 at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1347) at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1280) at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:78) ... 1 more Caused by: org.hibernate.exception.GenericJDBCException: Invalid argument in JDBC call: parameter index out of range: 4 at org.hibernate.exception.internal.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:148) at org.hibernate.exception.internal.SQLStateConverter.convert(SQLStateConverter.java:136) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:124) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109) at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:131) at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:80) at $Proxy12.setInt(Unknown Source) at org.hibernate.type.descriptor.sql.IntegerTypeDescriptor$1.doBind(IntegerTypeDescriptor.java:57) at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:82) at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:305) at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:300) at org.hibernate.type.ComponentType.nullSafeSet(ComponentType.java:358) at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2599) at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2836) at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3276) at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:80) at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:273) at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:265) at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:186) at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:344) at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50) at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1084) at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:319) at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:100) at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:173) at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:73) ... 1 more Caused by: java.sql.SQLException: Invalid argument in JDBC call: parameter index out of range: 4 at org.hsqldb.jdbc.Util.sqlException(Unknown Source) at org.hsqldb.jdbc.Util.sqlException(Unknown Source) at org.hsqldb.jdbc.Util.sqlException(Unknown Source) at org.hsqldb.jdbc.Util.outOfRangeArgument(Unknown Source) at org.hsqldb.jdbc.JDBCPreparedStatement.checkSetParameterIndex(Unknown Source) at org.hsqldb.jdbc.JDBCPreparedStatement.setInt(Unknown Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:124) ... 22 more Caused by: org.hsqldb.HsqlException: Invalid argument in JDBC call: parameter index out of range: 4 at org.hsqldb.error.Error.error(Unknown Source) ... 31 more I've also tested this with MySQL with the same JDBC exception. Note the workaround to resolve this is to put `..., insertable = false, updatable = false` onto the relationships' `@JoinColumn`s (but it's not really what I want). Please fix.

    Hibernate JIRA | 6 years ago | Karsten Wutzke
    javax.persistence.RollbackException: Error while committing the transaction
  3. Speed up your debug routine!

    Automated exception search integrated into your IDE

  4. 0

    The following mappings are all JPA 1.0 compatible (no derived identifiers): {code:Company.java} @Entity @Table(name = "Companies") public class Company { @Id @Column private Integer id; @Column private String name; ... } {code} {code:PQ.java} @Entity @Table(name = "PQs") public class PQ implements Serializable { @Id @Column private Integer id; @Column private String name; ... } {code} {code:Partnership.java} @Entity @Table(name = "Partnerships") @IdClass(value = PartnershipId.class) public class Partnership implements Serializable { @Id @Column(name = "pq_id", insertable = false, updatable = false) private Integer pqId; @Id @Column(name = "company_id", insertable = false, updatable = false) private Integer companyId; @Column(name = "ordinal_nbr") private Integer ordinalNbr; @ManyToOne @JoinColumn(name = "pq_id", referencedColumnName = "id") private PQ pq; @ManyToOne @JoinColumn(name = "company_id", referencedColumnName = "id") private Company company; ... } {code} {code:PartnershipId.java} public class PartnershipId implements Serializable { private Integer pqId; private Integer companyId; public PartnershipId() { } public PartnershipId(Integer pqId, Integer companyId) { this.pqId = pqId; this.companyId = companyId; } ... } {code} Note, the insertable = false, updatable = false on @JoinColumn relationships. Running the following test code {code:Main.java} public class Main { private static String PERSISTENCE_UNIT_NAME = "standalonePu"; private static EntityManagerFactory emf; private static EntityManager em; private static EntityTransaction trans; public static void main(String[] args) { setUp(PERSISTENCE_UNIT_NAME); trans.begin(); PQ detachedPq = new PQ(1, "Test PQ"); Company detachedCompany = new Company(1, "Test Company"); PQ pq = em.merge(detachedPq); Company company = em.merge(detachedCompany); Partnership detachedPartnership = new Partnership(1, 1, 1); detachedPartnership.setPQ(pq); detachedPartnership.setCompany(company); Partnership partnership = em.merge(detachedPartnership); partnership = em.find(Partnership.class, new PartnershipId(1, 1)); System.out.println("Persistent partnership = (" + partnership.getPQId() + ", " + partnership.getCompanyId() + ", " + partnership.getOrdinalNbr() + ")"); trans.commit(); close(); } private static void setUp(String puName) { emf = Persistence.createEntityManagerFactory(puName); em = emf.createEntityManager(); trans = em.getTransaction(); } private static void close() { em.close(); emf.close(); } } {code} fails with a really strange exception: ERROR: Invalid argument in JDBC call: parameter index out of range: 4 Exception in thread "main" javax.persistence.RollbackException: Error while committing the transaction at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:90) at main.Main.main(Main.java:44) Caused by: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Invalid argument in JDBC call: parameter index out of range: 4 at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1347) at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1280) at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:78) ... 1 more Caused by: org.hibernate.exception.GenericJDBCException: Invalid argument in JDBC call: parameter index out of range: 4 at org.hibernate.exception.internal.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:148) at org.hibernate.exception.internal.SQLStateConverter.convert(SQLStateConverter.java:136) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:124) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109) at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:131) at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:80) at $Proxy12.setInt(Unknown Source) at org.hibernate.type.descriptor.sql.IntegerTypeDescriptor$1.doBind(IntegerTypeDescriptor.java:57) at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:82) at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:305) at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:300) at org.hibernate.type.ComponentType.nullSafeSet(ComponentType.java:358) at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2599) at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2836) at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3276) at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:80) at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:273) at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:265) at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:186) at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:344) at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50) at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1084) at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:319) at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:100) at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:173) at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:73) ... 1 more Caused by: java.sql.SQLException: Invalid argument in JDBC call: parameter index out of range: 4 at org.hsqldb.jdbc.Util.sqlException(Unknown Source) at org.hsqldb.jdbc.Util.sqlException(Unknown Source) at org.hsqldb.jdbc.Util.sqlException(Unknown Source) at org.hsqldb.jdbc.Util.outOfRangeArgument(Unknown Source) at org.hsqldb.jdbc.JDBCPreparedStatement.checkSetParameterIndex(Unknown Source) at org.hsqldb.jdbc.JDBCPreparedStatement.setInt(Unknown Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:124) ... 22 more Caused by: org.hsqldb.HsqlException: Invalid argument in JDBC call: parameter index out of range: 4 at org.hsqldb.error.Error.error(Unknown Source) ... 31 more I've also tested this with MySQL with the same JDBC exception. Note the workaround to resolve this is to put `..., insertable = false, updatable = false` onto the relationships' `@JoinColumn`s (but it's not really what I want). Please fix.

    Hibernate JIRA | 6 years ago | Karsten Wutzke
    javax.persistence.RollbackException: Error while committing the transaction
  5. 0

    Grandparent / Parent / Child - "Relationship Issues"

    openxava | 1 year ago | e-sarge
    javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not insert: [org.openxava.school.model.Level3a]
Not finding the right solution?
Take a tour to get the most out of Samebug.

Tired of useless tips?

Automated exception search integrated into your IDE

Root Cause Analysis

  1. org.hsqldb.HsqlException

    Invalid argument in JDBC call: parameter index out of range: 4

    at org.hsqldb.error.Error.error()
  2. HyperSQL Database
    Error.error
    1. org.hsqldb.error.Error.error(Unknown Source)
    1 frame
  3. HSQLDB
    JDBCPreparedStatement.setInt
    1. org.hsqldb.jdbc.Util.sqlException(Unknown Source)
    2. org.hsqldb.jdbc.Util.outOfRangeArgument(Unknown Source)
    3. org.hsqldb.jdbc.JDBCPreparedStatement.checkSetParameterIndex(Unknown Source)
    4. org.hsqldb.jdbc.JDBCPreparedStatement.setInt(Unknown Source)
    4 frames
  4. Java RT
    Method.invoke
    1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    4. java.lang.reflect.Method.invoke(Method.java:601)
    4 frames
  5. org.hibernate.engine
    AbstractProxyHandler.invoke
    1. org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:124)
    2. org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:80)
    2 frames
  6. Unknown
    $Proxy12.setInt
    1. $Proxy12.setInt(Unknown Source)
    1 frame
  7. Hibernate
    AbstractTransactionImpl.commit
    1. org.hibernate.type.descriptor.sql.IntegerTypeDescriptor$1.doBind(IntegerTypeDescriptor.java:57)
    2. org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:82)
    3. org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:305)
    4. org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:300)
    5. org.hibernate.type.ComponentType.nullSafeSet(ComponentType.java:358)
    6. org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2599)
    7. org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2836)
    8. org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3276)
    9. org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:80)
    10. org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:273)
    11. org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:265)
    12. org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:186)
    13. org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:344)
    14. org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
    15. org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1084)
    16. org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:319)
    17. org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:100)
    18. org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:173)
    18 frames
  8. Hibernate EJB
    TransactionImpl.commit
    1. org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:73)
    1 frame
  9. main
    Main.main
    1. main.Main.main(Main.java:44)
    1 frame