-->
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.  [ 2 posts ] 
Author Message
 Post subject: How to write a hql with composite key?
PostPosted: Sun Feb 04, 2007 10:35 pm 
Newbie

Joined: Wed Jan 31, 2007 9:55 pm
Posts: 16
Hi,

After playing around some time, I finally sort out how to use XDoclet to generate a table with composite key by having two classes while one class for Primary key properties

However, I don't know how to write the hql as the primary keys are under another java class.

If only one java class, I can write something like this
from BatchControl ct where ct.resourceName = :resource_name and batchId = :batch_id

But, since the resourceName and batchId are on BatchConrolCompositeKey class but I want to return the whole BatchControl.

How can I write the hql then?

public class BatchControl implements Serializable {
private BatchControlCompositeKey key;
private String attribute;
private Timestamp lastUpdate;
private String status;

public BatchControlCompositeKey getKey() {
return key;
}
public void setKey(BatchControlCompositeKey key) {
this.key = key;
}
public String getAttribute() {
return attribute;
}
public void setAttribute(String attribute) {
this.attribute = attribute;
}
public Timestamp getLastUpdate() {
return lastUpdate;
}
public void setLastUpdate(Timestamp lastUpdate) {
this.lastUpdate = lastUpdate;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
}


public class BatchControlCompositeKey implements Serializable {
private String resourceName;
private long batchId;

public String getResourceName() {
return resourceName;
}
public void setResourceName(String resourceName) {
this.resourceName = resourceName;
}
public long getBatchId() {
return batchId;
}
public void setBatchId(long batchId) {
this.batchId = batchId;
}
public boolean equals(Object o) {
if (o == null) {
return false;
}
if (getClass().equals(o.getClass()) &&
resourceName.equals(((BatchControlCompositeKey) o).getResourceName()) &&
batchId == ((BatchControlCompositeKey) o).getBatchId() ) {
return true;
}
else {
return false;
}
}
public int hashCode() {
return resourceName.hashCode();
}
}


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 04, 2007 11:04 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Code:
from BatchControl ct where ct.key.resourceName = :resource_name and ct.key.batchId = :batch_id

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.