-->
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: composite key + jpa query
PostPosted: Wed Aug 01, 2007 9:41 am 
Newbie

Joined: Wed Aug 01, 2007 9:26 am
Posts: 2
I have a database that I can't change It's structure and need to query over tables with composite keys

I'm trying to use the documentation strategy :

I have a fee pojo class named Fee and an Iten pojo class

The last one has a composite key with two atributes: Fee and ItemFee

I created a class named ItemPK and added two atributtes Fee and itemFee

In my Item pojo I added :
@EmbeddedId
private ItemPK id;

When I try to run a query :

select i from Item i where i.id.fee.fee = :x

I get this error :

Caused by: org.hibernate.QueryException: could not resolve property: cobranca of
: item.Item [select i from item.Item
i where i.id.fee.fee = :fee]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 05, 2007 2:25 pm 
Newbie

Joined: Wed Sep 05, 2007 1:49 pm
Posts: 2
Hi,

I had the same problem and I solved it very dirty, with selecting all Rows and selecting all relevant in a while-loop by copying them in a new List. *shiver* ;-)

If someone has got a better solution I'd appreciate it if you could please let me know.

geets

Nico


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 06, 2007 8:21 am 
Newbie

Joined: Wed Sep 05, 2007 1:49 pm
Posts: 2
I think this could be a solution:


Code:
Session session = (Session) em.getDelegate();
ForeignKeyClass k = em.find(ForeignKeyClass.class,yourId);
Criteria crit = session.createCriteria(TableWithFK.class)
    .add(Restrictions.eq( "fk_class", k));
ArrayList a = (ArrayList)crit.list();
a.isEmpty(); // just a breakspoint line
session.close();


but this criteria doesn't delete itself after using and I didn't find a way to unset this. So every Query uses this criteria after setting it.

greets

Nico


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.