[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-1528?page=c...
]
Rob Hasselbaum commented on HHH-1528:
-------------------------------------
Still a problem in Hibernate 3.2.2. There is no binding for the ID parameter in the
PreparedStatement because of the empty OneToOneType.nullSafeSet method. Appears to have
been implemented that way on purpose, but I don't know why. Here's the example
I've been working with:
public class Person {
private Long m_id;
private Name m_name;
// ... getters and setters not shown ...
}
public class Name {
private Long m_id;
private Person m_person;
// ... getters and setters not shown ...
}
Mapped as follows:
<class name="Person" table="tbl_person">
<id name='id' column='objid'>
<generator class='native' />
</id>
<one-to-one name="name" class="Name"
property-ref="person" cascade="all"/>
</class>
<class name="Name" table="tbl_name">
<id name='id' column='objid'>
<generator class='native' />
</id>
<many-to-one name="person" class="Person"
column="person_id" not-null="true" unique="true"/>
</class>
The following code should work, but doesn't:
Person p = new Person();
Name n = new Name();
p.setName(n);
Session sess = getSessionFactory().getCurrentSession();
sess.save(p);
sess.flush();
sess.clear();
Query q = sess.createQuery("from Person p where p.name = :name");
q.setParameter("name", n);
List result = q.list(); // FAILS!
GenericJDBCException when querying on one-to-one association
------------------------------------------------------------
Key: HHH-1528
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-1528
Project: Hibernate3
Type: Bug
Versions: 3.1.2
Environment: Hibernate 3.1.2, MySQL 4.1, Java 5
Reporter: Alexander Dvorkovyy
Attachments: src.zip
I am getting following stack trace:
Exception in thread "main" org.hibernate.exception.GenericJDBCException: could
not execute query
at
org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:91)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:79)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2148)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
at org.hibernate.loader.Loader.list(Loader.java:2024)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:375)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:308)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:153)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1129)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at BugDemo.main(BugDemo.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:86)
Caused by: java.sql.SQLException: Statement parameter 1 not set.
at
com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:1031)
at
com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:676)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1030)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:139)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1669)
at org.hibernate.loader.Loader.doQuery(Loader.java:662)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2145)
... 13 more
while executing this code:
OneClass one = (OneClass) session.load(OneClass.class, 1L);
Query query = session.createQuery("FROM OneToOneClass oto WHERE
oto.whatever=:whatever");
query.setParameter("whatever", one);
query.list(); // < - - Exception is thrown here
on this domain model (I used annotations here, same thing with hbm.xml):
@Entity public class OneClass {
@Id private Long id;
}
@Entity public class OneToOneClass {
@Id private Long id;
@OneToOne
@PrimaryKeyJoinColumn
private OneClass whatever;
}
Problem first appeared in 3.1 (also when using xml mapping files), in 3.0 no problem.
Full source code attached.
Would be nice if the problem can be fixed in upcoming 3.1.3
--
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