-->
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.  [ 3 posts ] 
Author Message
 Post subject: Quering part of a composite id
PostPosted: Thu Nov 08, 2007 3:37 pm 
Newbie

Joined: Mon Oct 29, 2007 11:50 am
Posts: 5
Hi everyone.
Im trying to do a simple query that uses only part of a composite id and other attribute of an entity, but, no matter how much i try, i still having de same problem.

I searched for this problem in the forum and cannot find a solution or a tip.

The problem is: when I do this
Code:
Query q = em.createQuery("select c from Customer c where c.dId=:dId and c.first=:first");


I get the following exception:
Code:
Exception in thread "main" java.lang.IllegalArgumentException: org.hibernate.QueryException: could not resolve property: dId of: model.Customer [select c from model.Customer c where c.dId=:dId and c.first=:first]


This is strange by the fact that I have this attribute in the class Customer.

Code:
@Id
   @Column(name = "C_D_ID")
   public Long getDId() {
      return dId;
   }


I tried to use @EmbeddedId and got the same error.

Can anyone help me?

PS: Im using:
INFO [main] (Log4JLogger.java:94) - Hibernate Annotations 3.3.0.GA
INFO [main] (Log4JLogger.java:94) - Hibernate 3.2.5

Thanks in advance.

Murilo


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 20, 2007 7:12 am 
Newbie

Joined: Mon Oct 29, 2007 11:50 am
Posts: 5
Hi again.
After two weeks without my notebook due to electrical problem, here I am again.

I made another tests.

Query q = entityManager.createQuery("from Customer c where c.dId=:dId"); produces:
org.hibernate.QueryException: could not resolve property: dId of: model.Customer [from model.Customer c where c.dId=:dId]

Query q = entityManager.createQuery("from Customer c where c.first=:first"); works fine!

The only difference between the two attributes is that dId is anotated with @Id and first don't.

Almost all kind of operations works. Im able to insert, update, delete and even do a entityManager.find(Customer.class, new instance of CustomerPk).

The problem is with quering only part of composite id.

Have anyone an idea why this happens?

Thanks again.

Murilo


Top
 Profile  
 
 Post subject: [Fixed] - Is this a bug?
PostPosted: Fri Nov 23, 2007 9:12 am 
Newbie

Joined: Mon Oct 29, 2007 11:50 am
Posts: 5
Hi again.

Tired of trying a lot of different ways and always getting the same error, i decided to abandon the EntityManager and Annotations and try de HBM mapping files.

So, I mapped my District class in this way:
Code:
<hibernate-mapping>
   <class name="model.District">
      <composite-id class="model.DistrictPK" mapped="true">
         <key-property name="id" column="D_ID" />
         <key-property name="wId" column="D_W_ID" />
      </composite-id>
      
      <property name="name" type="string" column="D_NAME" length="10" />
      <property name="street1" type="string" column="D_STREET_1" length="20" />
      <property name="street2" type="string" column="D_STREET_2" length="20" />
      <property name="city" type="string" column="D_CITY" length="20" />
      <property name="state" type="string" column="D_STATE" length="2" />
      <property name="zip" type="string" column="W_ZIP" length="9" />
      <property name="tax" type="float" column="D_TAX" scale="0" precision="4" />
      <property name="ytd" type="float" column="D_YTD" scale="12" precision="0" />
      <property name="nextOId" type="long" column="D_NEXT_O_ID" />
      
      <many-to-one name="warehouse" class="model.Warehouse" insert="false" update="false">
         <column name="D_W_ID" />
      </many-to-one>
   </class>
</hibernate-mapping>


For my surprise, the same error appeared at this point:
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
And this was worst because I havent mapped the Customer class, where I was used to find the problem.

The exception was: unable to find a getter for wId atribute. I certified my self and THERE WAS a getter for this attribute.

I thought, maybe there is a problem attribute`s name.

So I decided to try something that, at that time, didnt made any sense for me. I returned to the old project (EntityManager and Annotations) and changed the name of the attribute from dId to districtId in the Customer class. Generated the appropriate setters and getters and run a test. The same test:

Query q = em.createQuery("from Customer c where c.districtId=:districtId");

Result: That works!!!

So, the question is: Does this make sense for you?

Murilo


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