javax.persistence.PersistenceException

tip

Check if you're not creating unused SQL entities, as it might cause this exception.


rafael

You have a different solution? A short tip here would help you and many other users who saw this issue last week.

  • Hibernate fails to query OneToOne association from the non-owning side when there is a reference inside the where clause. The behaviour was observed on both Hibernate 3.5.6 and 3.6.0 and tested in H2 and PostgreSQL environments. Given two entities: {code:java} @Entity public class Frame implements Serializable { @Id private long id; @OneToOne private Picture picture; } @Entity public class Picture implements Serializable { @Id private long id; @OneToOne(mappedBy = "picture") private Frame frame; } {code} If the query is issued from the owning side of the association, everything works as expected. {code} Picture pictureRef = entityManager.getReference(Picture.class, 5L); // id exists // list Frames by Picture reference (works) List<Frame> frames = entityManager.createQuery("from Frame f where f.picture = :picture", Frame.class) .setParameter("picture", pictureRef) .getResultList(); {code} However, if the query is issued from the non-owning side, the exception is thrown. {code} Frame frameRef = entityManager.getReference(Frame.class, 3L); // id exists // list Pictures by Frame reference (crashes!) List<Picture> pictures = entityManager.createQuery("from Picture p where p.frame = :frame", Picture.class) .setParameter("frame", frameRef) .getResultList(); {code} The stacktrace produced with H2 database used: {noformat} javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute query at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1214) at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1147) at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:255) at issue.OneToOneIssueMain.query2(OneToOneIssueMain.java:83) at issue.OneToOneIssueMain.run(OneToOneIssueMain.java:29) at issue.OneToOneIssueMain.main(OneToOneIssueMain.java:19) Caused by: org.hibernate.exception.GenericJDBCException: could not execute query at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140) at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) at org.hibernate.loader.Loader.doList(Loader.java:2536) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276) at org.hibernate.loader.Loader.list(Loader.java:2271) at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:452) at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363) at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196) at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1268) at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102) at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:246) ... 3 more Caused by: org.h2.jdbc.JdbcSQLException: Parameter "#1" is not set; SQL statement: select picture0_.id as id1_ from Picture picture0_ where picture0_.id=? [90012-143] at org.h2.message.DbException.getJdbcSQLException(DbException.java:327) at org.h2.message.DbException.get(DbException.java:167) at org.h2.message.DbException.get(DbException.java:144) at org.h2.expression.Parameter.checkSet(Parameter.java:73) at org.h2.command.Prepared.checkParameters(Prepared.java:161) at org.h2.command.CommandContainer.query(CommandContainer.java:79) at org.h2.command.Command.executeQuery(Command.java:132) at org.h2.jdbc.JdbcPreparedStatement.executeQuery(JdbcPreparedStatement.java:96) at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208) at org.hibernate.loader.Loader.getResultSet(Loader.java:1953) at org.hibernate.loader.Loader.doQuery(Loader.java:802) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274) at org.hibernate.loader.Loader.doList(Loader.java:2533) ... 11 more {noformat}
    via by Martin Striz,
  • Hibernate fails to query OneToOne association from the non-owning side when there is a reference inside the where clause. The behaviour was observed on both Hibernate 3.5.6 and 3.6.0 and tested in H2 and PostgreSQL environments. Given two entities: {code:java} @Entity public class Frame implements Serializable { @Id private long id; @OneToOne private Picture picture; } @Entity public class Picture implements Serializable { @Id private long id; @OneToOne(mappedBy = "picture") private Frame frame; } {code} If the query is issued from the owning side of the association, everything works as expected. {code} Picture pictureRef = entityManager.getReference(Picture.class, 5L); // id exists // list Frames by Picture reference (works) List<Frame> frames = entityManager.createQuery("from Frame f where f.picture = :picture", Frame.class) .setParameter("picture", pictureRef) .getResultList(); {code} However, if the query is issued from the non-owning side, the exception is thrown. {code} Frame frameRef = entityManager.getReference(Frame.class, 3L); // id exists // list Pictures by Frame reference (crashes!) List<Picture> pictures = entityManager.createQuery("from Picture p where p.frame = :frame", Picture.class) .setParameter("frame", frameRef) .getResultList(); {code} The stacktrace produced with H2 database used: {noformat} javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute query at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1214) at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1147) at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:255) at issue.OneToOneIssueMain.query2(OneToOneIssueMain.java:83) at issue.OneToOneIssueMain.run(OneToOneIssueMain.java:29) at issue.OneToOneIssueMain.main(OneToOneIssueMain.java:19) Caused by: org.hibernate.exception.GenericJDBCException: could not execute query at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140) at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) at org.hibernate.loader.Loader.doList(Loader.java:2536) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276) at org.hibernate.loader.Loader.list(Loader.java:2271) at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:452) at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363) at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196) at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1268) at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102) at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:246) ... 3 more Caused by: org.h2.jdbc.JdbcSQLException: Parameter "#1" is not set; SQL statement: select picture0_.id as id1_ from Picture picture0_ where picture0_.id=? [90012-143] at org.h2.message.DbException.getJdbcSQLException(DbException.java:327) at org.h2.message.DbException.get(DbException.java:167) at org.h2.message.DbException.get(DbException.java:144) at org.h2.expression.Parameter.checkSet(Parameter.java:73) at org.h2.command.Prepared.checkParameters(Prepared.java:161) at org.h2.command.CommandContainer.query(CommandContainer.java:79) at org.h2.command.Command.executeQuery(Command.java:132) at org.h2.jdbc.JdbcPreparedStatement.executeQuery(JdbcPreparedStatement.java:96) at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208) at org.hibernate.loader.Loader.getResultSet(Loader.java:1953) at org.hibernate.loader.Loader.doQuery(Loader.java:802) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274) at org.hibernate.loader.Loader.doList(Loader.java:2533) ... 11 more {noformat}
    via by Martin Striz,
  • H2 Oracle decode function
    via Stack Overflow by SvRekaa
    ,
  • Failover @Type for h2?
    via Stack Overflow by xenoterracide
    ,
  • Ebean/idIn Parameter not set
    via Stack Overflow by Janus Troelsen
    ,
  • Remote procedure call error
    via GitHub by milci199
    ,
    • javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute query at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1214) at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1147) at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:255) at issue.OneToOneIssueMain.query2(OneToOneIssueMain.java:83) at issue.OneToOneIssueMain.run(OneToOneIssueMain.java:29) at issue.OneToOneIssueMain.main(OneToOneIssueMain.java:19) Caused by: org.hibernate.exception.GenericJDBCException: could not execute query at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140) at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) at org.hibernate.loader.Loader.doList(Loader.java:2536) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276) at org.hibernate.loader.Loader.list(Loader.java:2271) at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:452) at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363) at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196) at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1268) at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102) at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:246) ... 3 more Caused by: org.h2.jdbc.JdbcSQLException: Parameter "#1" is not set; SQL statement: select picture0_.id as id1_ from Picture picture0_ where picture0_.id=? [90012-143] at org.h2.message.DbException.getJdbcSQLException(DbException.java:327) at org.h2.message.DbException.get(DbException.java:167) at org.h2.message.DbException.get(DbException.java:144) at org.h2.expression.Parameter.checkSet(Parameter.java:73) at org.h2.command.Prepared.checkParameters(Prepared.java:161) at org.h2.command.CommandContainer.query(CommandContainer.java:79) at org.h2.command.Command.executeQuery(Command.java:132) at org.h2.jdbc.JdbcPreparedStatement.executeQuery(JdbcPreparedStatement.java:96) at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208) at org.hibernate.loader.Loader.getResultSet(Loader.java:1953) at org.hibernate.loader.Loader.doQuery(Loader.java:802) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274) at org.hibernate.loader.Loader.doList(Loader.java:2533) ... 11 more

    Users with the same issue

    aidoan
    1 times, last one,
    kjhdofjosvs
    1 times, last one,
    Unknown visitor1 times, last one,
    Unknown visitor1 times, last one,
    Unknown visitor1 times, last one,
    144 more bugmates