Hello,
I'm having trouble writing a simple join query between two tables. Note that I inherited a db with composite keys on all tables that include:
int id
in classId
So all of my entity classes start out like this:
Code:
@Entity
@Table(name = "rp.batch")
public class HBatch {
private HBatchId key;
public HBatch() {
}
// Property accessors
@EmbeddedId
@AttributeOverrides( {
@AttributeOverride(name="id", column=@Column(name="id", unique=false, nullable=false, insertable=true, updatable=true) ),
@AttributeOverride(name="classId", column=@Column(name="classId", unique=false, nullable=false, insertable=true, updatable=true) ) } )
public HBatchId getKey() {
return this.key;
}
public void setKey(HBatchId key) {
this.key = key;
}
...
With of course, the requisite key class:
Code:
@Embeddable
public class HBatchId implements java.io.Serializable {
// Fields
private int id;
private int classId;
...
I have two classes in particular, HBatch and HTransfer. I need to write a query in hibernate that looks like this in normal SQL:
Code:
select b.* from rp.batch b, rp.transfer t where t.batchId = b.id and t.batchClassId = b.classId and t.invoiceId = 109
First of all, the table transfer has both parts of the composite key that belongs to batch, transfer.batchId and transfer.batchClassId both are foreign keys to the batch.id and batch.classId columns, though I do not know how or if that should be represented in the transfer entity class. Secondly that the last value (109) actually should be a variable.
I could handle the simple join IF it weren't for the fact that this was a friggin' composite key. Could someone please help me with a hibernate query of any sort that will produce the same results as the sql mentioned above?
Setup Info:
Hibernate version: Core 3.3.1 GA, Annotations 3.4.0
Mapping documents: hibernate.cfg.xml
Regards,
Tim