-->
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.  [ 2 posts ] 
Author Message
 Post subject: Problems with Query by Criteria and Many-to-One
PostPosted: Wed Apr 06, 2005 12:46 pm 
Newbie

Joined: Tue Apr 05, 2005 11:03 pm
Posts: 2
When I try to define a query by criteria on an object with a many to one relationship, it throws an IllegalArgumentException on the referred to object. Anyone have any ideas on what is causing this? When I change to using HQL instead, it seems to all work correctly.

Many thanks for any help.
Ben

Version: Hibernate 3 (Not RC1)

Request Class has a many to one relation with EntityPO
...
Code:
<many-to-one
        name="EntityByApproverEntityId"
        class="cat.EntityPO"
        not-null="true" cascade="none" lazy="false"
    >
        <column name="APPROVER_ENTITY_ID" />
</many-to-one>

...
Here's the table def for Request:
CAR_ID NOT NULL NUMBER(10)
REQUEST_TYPE_CODE NOT NULL CHAR(1)
PROCESSED_DATETIME DATE
REQUEST_STATE_CODE NOT NULL CHAR(1)
REQUESTER_ENTITY_ID NOT NULL NUMBER(10)
APPROVER_ENTITY_ID NOT NULL NUMBER(10)
LOGIN_ID VARCHAR2(50)
AFFILIATED_ORG_CODE VARCHAR2(30)
SUBMITTED_DATETIME DATE
APPROVED_DATETIME DATE
DELEGATE_ENTITY_ID NUMBER(10)


EntityPO Class has this:
...
Code:
<set
        name="CWSAccountRequestsByApproverEntityId"
        lazy="false"
        inverse="false"
      cascade="none"
    >
       
        <key>
            <column name="APPROVER_ENTITY_ID" />
        </key>
        <one-to-many
            class="cat.CWSAccountRequestPO"
        />
       
</set>


Here's the table def for Entity:
ENTITY_ID NOT NULL NUMBER(10)
ENTITY_TYPE_CODE NOT NULL CHAR(1)
FIRST_NAME NOT NULL VARCHAR2(30)
LAST_NAME NOT NULL VARCHAR2(30)
MIDDLE_INITIAL VARCHAR2(10)
EMAIL_ADDRESS VARCHAR2(100)
CUPID VARCHAR2(32)
PHONE_NUMBER VARCHAR2(25)


Oracle 9.2.0

Here's the code that I use:

Code:
criteria = session.createCriteria(CWSAccountRequestPO.class);
criteria.add(Expression.eq("requestTypeCode", Constants.REQUEST_TYPE_NEW));
criteria.add(Expression.in("EntityByApproverEntityId", approverIds));
retVal = criteria.list();


The query looks fine. Here it is:
Code:
select this_.CAR_ID as CAR1_0_, this_.REQUEST_TYPE_CODE as REQUEST2_0_0_, this_.PROCESSED_DATETIME as PROCESSED3_0_0_, this_.REQUEST_STATE_CODE as REQUEST4_0_0_, this_.LOGIN_ID as LOGIN5_0_0_, this_.AFFILIATED_ORG_CODE as AFFILIATED6_0_0_, this_.SUBMITTED_DATETIME as SUBMITTED7_0_0_, this_.APPROVED_DATETIME as APPROVED8_0_0_, this_.DELEGATE_ENTITY_ID as DELEGATE9_0_0_, this_.APPROVER_ENTITY_ID as APPROVER10_0_0_, this_.REQUESTER_ENTITY_ID as REQUESTER11_0_0_ from CWS_ACCOUNT_REQUESTS this_ where this_.REQUEST_TYPE_CODE=? and this_.APPROVER_ENTITY_ID in (?)


Here's the stack trace I see.
Code:
org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of cat.cis.portal.supplier.CWSHelp.persistence.EntityPO.entityId
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:170)
   at junit.framework.TestResult.runProtected(TestResult.java:135)
   at junit.framework.TestResult.run(TestResult.java:112)
   at junit.framework.TestCase.run(TestCase.java:119)
   at junit.framework.TestSuite.runTest(TestSuite.java:209)
   at junit.framework.TestSuite.run(TestSuite.java:205)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:399)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:288)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:170)
   at junit.framework.TestSuite.run(TestSuite.java:205)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:399)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:288)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:170)
   at org.hibernate.loader.Loader.list(Loader.java:1498)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:170)
Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
   at org.hibernate.tuple.AbstractTuplizer.getIdentifier(AbstractTuplizer.java:117)
   at org.hibernate.persister.entity.BasicEntityPersister.getIdentifier(BasicEntityPersister.java:2947)
   at org.hibernate.persister.entity.BasicEntityPersister.isTransient(BasicEntityPersister.java:2752)
   at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:185)
   at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:217)
   at org.hibernate.type.EntityType.getIdentifier(EntityType.java:94)
   at org.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:50)
   at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1045)
   at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1130)
   at org.hibernate.loader.Loader.doQuery(Loader.java:415)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:212)
   at org.hibernate.loader.Loader.doList(Loader.java:1532)
   at org.hibernate.loader.Loader.list(Loader.java:1498)
   at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:111)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1262)
   at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:302)
   at cat.cis.portal.supplier.CWSHelp.factory.RequestFactory.getNewRequestsForApprover(RequestFactory.java:95)
   at cat.cis.portal.supplier.CWSHelp.factory.RequestFactoryTest.testGetNewRequestsForApproverWithArray(RequestFactoryTest.java:77)
   at java.lang.reflect.Method.invoke(Native Method)
   at junit.framework.TestCase.runTest(TestCase.java:164)
   at junit.framework.TestCase.runBare(TestCase.java:132)
   at junit.framework.TestResult$1.protect(TestResult.java:107)
   at junit.framework.TestResult.runProtected(TestResult.java:135)
   at junit.framework.TestResult.run(TestResult.java:112)
   at junit.framework.TestCase.run(TestCase.java:119)
   at junit.framework.TestSuite.runTest(TestSuite.java:209)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:288)



Top
 Profile  
 
 Post subject: The solution
PostPosted: Thu Apr 07, 2005 3:48 pm 
Newbie

Joined: Tue Apr 05, 2005 11:03 pm
Posts: 2
So here's the solution to my problem. I should have put the following:

criteria.add(Expression.in("EntityByApproverEntityId.entityId", approverIds));

Or...

criteria.add(Expression.in("EntityByApproverEntityId.id", approverIds));

Something is still wierd with the error message and it was still more difficult to figure out, but at least I have a solution.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.