-->
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: how to construct a HQL query when using a composite key
PostPosted: Mon Jan 09, 2006 9:42 am 
Newbie

Joined: Mon Jan 09, 2006 8:17 am
Posts: 19
hi (from a newbie),

Can someone help me as to how to construct a HQL query when there is a composite key involved.

It is a simple table with the following 2 fields as primary keys:

table = Auction

pkey 1 = auction_number
pkey 2 = lot_number

i used hibernate console to generate POJOs.

The 2 keys become part of a class generated.

snapshot of the CreateQuery i did:

"from Auction auction where auction.id = :auction_id"

.setParameter("auction_id", auction_id).

it returned a exception.

2 questions:

1. how do i query just using only pkey "auction_number" to return only those records having this "auction_number" ?

2. how to set the values in the 2 pkeys before executing the query ?

Thanks for helping


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 09, 2006 2:23 pm 
Newbie

Joined: Fri Oct 14, 2005 3:47 pm
Posts: 5
Location: Israel
1. String query="from Auction auction where auction.comp_id.auction_number=:auction_number and auction.comp_id.lot_number =:lot_number";

comp_id this is member in Auction and instance of AuctionPk class

2. session.createQuery(query)
.setParameter("comp_id.auction_number", an)
.setParameter("comp_id.lot_number", ln)
.list();[/code]


Top
 Profile  
 
 Post subject: RE: how to construct a HQL query when using a composite key
PostPosted: Tue Jan 10, 2006 8:45 am 
Newbie

Joined: Mon Jan 09, 2006 8:17 am
Posts: 19
hi Dimka,

Thanks ... u gave me a hint as to how to solve the problem. The .setParam created a 'named parameter not found' error.
It should be just:

.setParameter("an",an);
.setParameter("ln",ln);

That made it work ... unless i am missing something else from your response. Nevertheless, thanks it helped me work it out.


Dimka wrote:
1. String query="from Auction auction where auction.comp_id.auction_number=:auction_number and auction.comp_id.lot_number =:lot_number";

comp_id this is member in Auction and instance of AuctionPk class

2. session.createQuery(query)
.setParameter("comp_id.auction_number", an)
.setParameter("comp_id.lot_number", ln)
.list();[/code]


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.