-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Subqueries.in VS Property.forname().in
PostPosted: Tue Jun 14, 2005 6:51 am 
Newbie

Joined: Tue Jun 14, 2005 6:41 am
Posts: 10
Hibernate version:

3.0.5

Description:

What is the difference between

".add(Subqueries.in("id", unique))" and ".add(Property.forName("id").in(unique))"?

I get a exception from the code below, but if I change to the properties version, it works just fine. Docs are not very expressive on this matter... afaik :)



Code:

DetachedCriteria unique = DetachedCriteria.forClass(Work.class, "unique")
.setProjection(Projections.projectionList().add(Projections.max("id")))
.add(Restrictions.eq("status", new Status(Status.FINISHED_FAILED)))
.add(Restrictions.eqProperty("unique.userFileName", "failure.userFileName"))
.createCriteria("user").add(Restrictions.eq("customer", customer));

Criteria criteria = session.createCriteria(Work.class, "failure")
.addOrder(Order.desc("id"))
.add(Restrictions.eq("status", new Status(Status.FINISHED_FAILED)))
.add(Restrictions.in("worktype", new Object[] {new WorkType(WorkType.CHANGE), new WorkType(WorkType.CHANGEDATATEST)}))
.add(Restrictions.not(Subqueries.in("userFileName", success)))
.add(Subqueries.in("id", unique))
//.add(Property.forName("id").in(unique))
.createCriteria("user").add(Restrictions.eq("customer", customer));
return criteria.list();

Full stack trace of any exception that occurs:

java.lang.ClassCastException: java.lang.String
at org.hibernate.type.IntegerType.set(IntegerType.java:39)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:62)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:44)
at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1115)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1177)
at org.hibernate.loader.Loader.doQuery(Loader.java:390)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.doList(Loader.java:1593)
at org.hibernate.loader.Loader.list(Loader.java:1577)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:111)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 14, 2005 8:38 am 
Newbie

Joined: Tue Jun 14, 2005 6:41 am
Posts: 10
Not sure if this is related, but I keep getting there classcastexceptions for just about anything now.

Mapping:

<!--
MUNICIPALITY
-->
<class name="se.lantmateriet.jollen.bryggan.domain.Municipality" table="ACCESS_AREAS" mutable="false">
<id name="id" column="NAME" type="string">
<generator class="assigned"/>
</id>
<property name="name" column="DESCRIPTION" type="string"/>
</class>


<!--
SUBSCRIPTION
-->
<class name="se.lantmateriet.jollen.bryggan.domain.Subscription" table="SUBSCRIPTIONS">
<id name="id" column="SUBSCRIPTIONID" type="integer">
<generator class="sequence">
<param name="sequence">ID_SEQ</param>
</generator>
</id>
<component name="municipality" class="se.lantmateriet.jollen.bryggan.domain.Municipality">
<property name="id" column="CMCODE" type="string"/>
</component>
<set name="deliveries" cascade="all,delete-orphan" inverse="true">
<key column="SUBSCRIPTIONID"/>
<one-to-many class="se.lantmateriet.jollen.bryggan.domain.Delivery"/>
</set>
<many-to-one name="customer" class="se.lantmateriet.jollen.bryggan.domain.Customer" column="CUSTOMERID" fetch="join"/>
</class>

Code:

cmCode is defined as final String.

This works:

Criteria criteria = session.createCriteria(Subscription.class)
.createCriteria("municipality") .add(Restrictions.eq("municipality.id", cmCode));
return criteria.list();

This fails:


Criteria criteria = session.createCriteria(Subscription.class)
.createCriteria("municipality").add(Restrictions.eq("id", cmCode));
return criteria.list();

Traceback:

java.lang.ClassCastException: java.lang.String
at org.hibernate.type.IntegerType.set(IntegerType.java:39)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:62)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:44)
at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1115)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1177)
at org.hibernate.loader.Loader.doQuery(Loader.java:390)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.doList(Loader.java:1593)
at org.hibernate.loader.Loader.list(Loader.java:1577)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:111)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1322)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:300)
at org.hibernate.impl.CriteriaImpl$Subcriteria.list(CriteriaImpl.java:142)
at se.lantmateriet.jollen.bryggan.dataaccess.hibernate.HibernateSubscriptionDAO$1.doInHibernate(HibernateSubscriptionDAO.java:39)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:312)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:288)
at se.lantmateriet.jollen.bryggan.dataaccess.hibernate.HibernateSubscriptionDAO.findByMunicipalityId(HibernateSubscriptionDAO.java:33)
at se.lantmateriet.jollen.bryggan.dataaccess.hibernate.HibernateSubscriptionDAOTest.testFindByMunicipalityId(HibernateSubscriptionDAOTest.java:31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)


Top
 Profile  
 
 Post subject: same with hibernate 3.1rc2
PostPosted: Sat Nov 05, 2005 1:34 am 
Newbie

Joined: Sat Nov 05, 2005 1:24 am
Posts: 5
I also had to use Property with Hibernate 3.1rc2, otherwise it wouldn't work either, but the error is slightly different as mentioned here. It says it cannot bind the parameter to the query. After changing to Property, it binds it correctly and everything works.

Actually, with Subquery it tries to bind the property name as the value. For example, if you have

Subqueries.eq("field1", dq)

it will try to bind the value "field1" (and not this field contents) as the subquery parameter.

Actually, for those with problems with subquery in 3.1rc2, try to check this issue in case you are hitting exceptions on your way:

http://opensource2.atlassian.com/projec ... se/HHH-957

There is a patch (I posted the version updated to hibernate 3.1rc2) that solves the ClassCastException reported there.


Top
 Profile  
 
 Post subject: Re: Subqueries.in VS Property.forname().in
PostPosted: Fri Feb 18, 2011 4:11 pm 
Newbie

Joined: Fri Feb 18, 2011 4:00 pm
Posts: 1
Hi,

I work with Hibernate 3.6.0.Final an I have the same problem as described below.

Is the bug still alive?

According to http://opensource.atlassian.com/project ... se/HHH-957, a patch has been published in a previous version.

Code:
DetachedCriteria dc = DetachedCriteria.forClass(MySubObject.class);
Disjunction or = Restrictions.disjunction();
...
or.add(
   Property.forName("id").in(dc)
);


works fine whereas :

Code:
DetachedCriteria dc = DetachedCriteria.forClass(MySubObject.class);
Disjunction or = Restrictions.disjunction();
...
or.add(
   Subqueries.in("id", dc)
);


doesn't work!

Does somebody has any idea?

Thanks!

Letskank

Here is the stacktrace :
Code:
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
   at org.hibernate.type.descriptor.java.IntegerTypeDescriptor.unwrap(IntegerTypeDescriptor.java:36)
   at org.hibernate.type.descriptor.sql.IntegerTypeDescriptor$1.doBind(IntegerTypeDescriptor.java:52)
   at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:89)
   at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:282)
   at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:277)
   at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1873)
   at org.hibernate.loader.Loader.bindParameterValues(Loader.java:1844)
   at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1716)
   at org.hibernate.loader.Loader.doQuery(Loader.java:801)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
   at org.hibernate.loader.Loader.doList(Loader.java:2533)
   at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
   at org.hibernate.loader.Loader.list(Loader.java:2271)
   at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:119)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1716)
   at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:347)
   ... 17 more


Hibernate log :
Code:
6766 [main] DEBUG org.hibernate.jdbc.AbstractBatcher  - preparing statement
6797 [main] DEBUG fcdq.grrope.rocr.modele.util.hibernate.UserTypeInteger  - binding parameter [2] as [INTEGER] - 1
6797 [main] DEBUG org.hibernate.type.descriptor.sql.BasicBinder  - binding parameter [3] as [INTEGER] - id


In the log, we can see that Hibernate is binding parameter "3" as an Integer instead of a String.


Top
 Profile  
 
 Post subject: Re: Subqueries.in VS Property.forname().in
PostPosted: Sat Dec 17, 2011 6:45 pm 
Newbie

Joined: Sun Aug 07, 2011 8:47 am
Posts: 2
letskank I've got similar problem in 3.6.8.Final. Have you found any solution?

Edit: Resolved - propertyIn


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.