[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-1528) GenericJDBCException when querying on one-to-one association

Rob Hasselbaum (JIRA) noreply at atlassian.com
Wed Feb 7 15:40:40 EST 2007


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1528?page=comments#action_26020 ] 

Rob Hasselbaum commented on HHH-1528:
-------------------------------------

This affects the Criteria API as well. In both cases, a workaround is to filter on the ID property of the associated object rather than the object itself. Modifying the code above, for example:

Query q = sess.createQuery("from Person p where p.name.id = :nameId");
q.setParameter("nameId", n.getId());
List result = q.list(); // WORKS!

> 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.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira




More information about the hibernate-issues mailing list