[hibernate-issues] [Hibernate-JIRA] Created: (HHH-5757) OneToOne SQL missing parameter
Martin Striz (JIRA)
noreply at atlassian.com
Fri Nov 26 02:26:16 EST 2010
OneToOne SQL missing parameter
------------------------------
Key: HHH-5757
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5757
Project: Hibernate Core
Issue Type: Bug
Affects Versions: 3.6.0, 3.5.6
Environment: Hibernate 3.5.6 / 3.6.0
H2 1.2.143 (in-memory) / PostgreSQL 9.0-801.jdbc4
Reporter: Martin Striz
Priority: Critical
Attachments: issue-test-case.zip
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}
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list