javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute query

Hibernate JIRA | Martin Striz | 6 years ago
  1. 0

    [HHH-5757] OneToOne SQL missing parameter - Hibernate JIRA

    atlassian.net | 1 year ago
    javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute query
  2. 0

    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}

    Hibernate JIRA | 6 years ago | Martin Striz
    javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute query
  3. 0

    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}

    Hibernate JIRA | 6 years ago | Martin Striz
    javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute query
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    H2 Oracle decode function

    Stack Overflow | 5 years ago | SvRekaa
    org.h2.jdbc.JdbcSQLException: Hexadecimal string with odd number of characters: "6.0"; SQL statement: select 6.0 - decode(1.0,2.0,3.0,4.0) from dual ; [90003-157]
  6. 0

    Failover @Type for h2?

    Stack Overflow | 2 years ago | xenoterracide
    org.h2.jdbc.JdbcSQLException: Hexadecimal string contains non-hex character: "aced0005-7372-000e-74c2-aa3c957d4f00"; SQL statement: select character0_.task_id as task_id1_0_0_, character0_.name as name2_0_0_ from characters character0_ where character0_.task_id=? [90004-176]

  1. kjhdofjosvs 1 times, last 4 weeks ago
6 unregistered visitors
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.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()
  2. H2 Database Engine
    JdbcPreparedStatement.executeQuery
    1. org.h2.message.DbException.getJdbcSQLException(DbException.java:327)
    2. org.h2.message.DbException.get(DbException.java:167)
    3. org.h2.message.DbException.get(DbException.java:144)
    4. org.h2.expression.Parameter.checkSet(Parameter.java:73)
    5. org.h2.command.Prepared.checkParameters(Prepared.java:161)
    6. org.h2.command.CommandContainer.query(CommandContainer.java:79)
    7. org.h2.command.Command.executeQuery(Command.java:132)
    8. org.h2.jdbc.JdbcPreparedStatement.executeQuery(JdbcPreparedStatement.java:96)
    8 frames
  3. Hibernate
    QueryLoader.list
    1. org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
    2. org.hibernate.loader.Loader.getResultSet(Loader.java:1953)
    3. org.hibernate.loader.Loader.doQuery(Loader.java:802)
    4. org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
    5. org.hibernate.loader.Loader.doList(Loader.java:2533)
    6. org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
    7. org.hibernate.loader.Loader.list(Loader.java:2271)
    8. org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:452)
    8 frames
  4. Hibernate HQL/JP-QL Parser
    QueryTranslatorImpl.list
    1. org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363)
    1 frame
  5. Hibernate
    QueryImpl.list
    1. org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
    2. org.hibernate.impl.SessionImpl.list(SessionImpl.java:1268)
    3. org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
    3 frames
  6. Hibernate EJB
    QueryImpl.getResultList
    1. org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:246)
    1 frame
  7. issue
    OneToOneIssueMain.main
    1. issue.OneToOneIssueMain.query2(OneToOneIssueMain.java:83)
    2. issue.OneToOneIssueMain.run(OneToOneIssueMain.java:29)
    3. issue.OneToOneIssueMain.main(OneToOneIssueMain.java:19)
    3 frames