-->
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.  [ 6 posts ] 
Author Message
 Post subject: HELP! HELP! URGENT!How to query a composite key class
PostPosted: Mon Jul 25, 2005 12:51 am 
Newbie

Joined: Thu Jul 21, 2005 10:25 pm
Posts: 4
I'm using myeclipse to develop my system.

I have a table named Tapplicationproject in my database.

When I generated the hibernate mapping using myeclipse, The following files were created:

- AbstractTapplicationproject.java
properties that I need (all are accessible from Tapplicationproject.java):
- description
- endDate
- id
- location
- role
- startDate
- tools

- Tapplicationproject.java
properties that I need: (NONE) but I'm using this class to access all fields because this is the child class of AbstractTapplicationproject.java

- TapplicationprojectKey.java
properties that I DESPERATELY need:
- applicationId
- projectName

- Tapplicationproject.hbm.xml

Now, I need to get ALL fields from Tapplicationproject table.

The problem is, the composite primary keys ('applicationId' & 'projectName' properties) are stored ONLY in the TapplicationprojectKey.java and I cannot query this class.

When I tried to query TapplicationprojectKey.java, the compiler said that TapplicationprojectKey is not a persistent class. So I have no idea how to query the 'applicationId' & 'projectName' from the TapplicationprojectKey using the HQL query.

Anyone know the way to work around this?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 25, 2005 2:22 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
DO NOT YELL on that forum, you won't get help this way.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 25, 2005 3:46 am 
Newbie

Joined: Thu Jul 21, 2005 10:25 pm
Posts: 4
sorry.. i didn't know upper case means yelling.. didn't mean to yell.. just thought that if I use capitals then it'll get someone's attention faster than not.. well, i guess, it did anyway..

so.. do you have any idea?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 25, 2005 4:04 am 
Beginner
Beginner

Joined: Tue Jul 19, 2005 4:03 am
Posts: 34
Location: Aberdeen, UK
We are using composite keys, but we are querying using Criteria, not HQL, which works just fine.

http://www.hibernate.org/hib_docs/reference/en/html/querycriteria.html

Though, we are not using custom types to represent our composite keys, but the composite-key element in the hibernate maps.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 25, 2005 7:16 am 
Newbie

Joined: Thu Jul 21, 2005 10:25 pm
Posts: 4
But, do you have a class named xxxxKey.java?

If you do have them, are you querying from that xxxxKey.java class or from xxxx.java (using criteria)?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 25, 2005 7:39 am 
Beginner
Beginner

Joined: Tue Jul 19, 2005 4:03 am
Posts: 34
Location: Aberdeen, UK
No, we are using the composite-id element in the maps:

Code:
<composite-id>
    <key-property name="ruleID" column="rule_id" type="java.lang.Integer">
         <meta attribute="use-in-equals">true</meta>
     </key-property>
     <key-property name="statatementID" column="statement_id" type="java.lang.Integer">
         <meta attribute="use-in-equals">true</meta>
       </key-property>
</composite-id>

So, I haven’t tried the using a custom key class (named xxxxKey.java). The map snipped form our statement.hbm.xml file and to get out the id’s from the composite keys using the criteria, we are using something like this code:

Code:
Criteria crit = sess.createCriteria(Statement.class);
List list = crit.list();

Statement myStatement = null;
Iterator elements = list.iterator();
while(elements.hasNext()){
     myStatement = (Statement) elements.next();
     System.out.println("Id: " + myStatement.get StatementID());     
}


My best suggestion is for you to try to use this approach. Then your code would (maybe) look something like this:


Code:
Criteria crit = sess.createCriteria(Tapplicationproject.class);
List list = crit.list();

Tapplicationproject myObject = null;
Iterator elements = list.iterator();
while(elements.hasNext()){
     myObject = (Tapplicationproject) elements.next();
     System.out.println("Id: " + myObject.getTapplicationprojectKey().getApplicationId())     
}


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