[Hibernate-JIRA] Created: (HHH-5757) OneToOne SQL missing parameter
by Martin Striz (JIRA)
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....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
14 years, 6 months
[Hibernate-JIRA] Created: (HHH-6112) ElementsCollection with List of Embeddables and FetchType.Eager result in wrong fetch
by Edmondo Porcu (JIRA)
ElementsCollection with List of Embeddables and FetchType.Eager result in wrong fetch
-------------------------------------------------------------------------------------
Key: HHH-6112
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6112
Project: Hibernate Core
Issue Type: Bug
Components: annotations
Affects Versions: 3.5.4
Environment: MYSQL 5, Hibernate Core and Annotation 3.5.4-Final
Reporter: Edmondo Porcu
Priority: Critical
Dear all,
a simple collection of embeddables who is not a set cannot be fetched correctly by Hibernate if one needs a fetchType.Eager .
@Column(nullable=true)
@IndexColumn(name="Ordinal")
@JoinColumn(name = "Curve_curveName")
@ElementCollection(fetch = FetchType.EAGER)
private List<CurveInstrument> oisList;
I have been forced to add the indexColumn to avoid fetching multiple bags at once, and this worked fine in persisting my objects. When i retrieve them from the database, however, my list contains only the first element of the collection I have persisted.
@Embeddable
public class CurveInstrument implements Serializable {
private static final long serialVersionUID = 4797265087176461985L;
private String name;
@Column(nullable=true)
@Type(type="org.hibernate.type.NumericBooleanType")
private boolean active = false;
@Column(nullable=true)
private double value=0;
@Column(nullable=true)
private double spread=0;
// Getters and setters
}
--
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....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
14 years, 6 months