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!
|