-->
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 select rows by a list of composite ids?
PostPosted: Thu Feb 07, 2008 10:50 am 
Newbie

Joined: Mon Jan 21, 2008 7:30 am
Posts: 9
I'm using Hibernate 3.2.5 and class annotations for defining my mappings.
I have a class with a 2 field composite id, which I define via an @Embeddable
PK class containing the 2 fields. The PK class is then specified as the @Id field in it's parent class. ie:

@Entity
@Table(name="PAYMENT")
@NamedQuery(name="payments.by.pks", query="from Payment pay where pay.id in (:pkList)")
public class Payment {

@Id
private PaymentPK pk;

// other fields....

}

@Embeddable
public class PaymentPK implements Serializable {

@Column(name = "CashflowId")
public String paymentId;

@Column(name = "VersionNumber")
public int versionNumber;

// implementations of equals and hashcode, getters, setters....

}




Ideally I want to be able to pass a list of composite id classes to a Hibernate namedQuery to return the list of matching rows. The raw sql for this query is of the form:

select * from PAYMENT p where ((p.idField1 = 'x' and p.idField2 = 'y') or (p.idField1 = 'a' and p.idField2 = 'b'))

When I execute
findByNamedQueryAndNamedParam("payments.by.pks","pkList", pks) where pks is a List<PaymentPK> the SQL which is generated is :

select xyz, abc
from
PAYMENT payment0_
where
(
payment0_.CashflowId, tiwpayment0_.VersionNumber
) in (
(
?, ?
) , (
?, ?
)
)

Running against Sybase 12.5 this generates a com.sybase.jdbc3.jdbc.SybSQLException: Incorrect syntax near ','. error.

Is this a bug in Hibernate? Am I doing something wrong? Your help is greatly appreciated!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 29, 2008 11:13 am 
Newbie

Joined: Mon Jan 21, 2008 7:30 am
Posts: 9
Can no one answer this question? Could this be due to the fact that the Sybase driver is broken?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 17, 2008 7:49 am 
Newbie

Joined: Mon Jan 21, 2008 7:30 am
Posts: 9
I'm still struggling with this problem... Can anyone please help??? I can't believe I'm the only one who has wanted to do this kind of query!!!


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.