Sorry, I'm not getting a response from Spring forum. They are saying this is more of a Hibernate question. Can someone help?
If I apply this query in the getHibernateTemplate() such as
public List getAllActivitiesGroupByTaskNo() {
log.info("get all activities: ");
return getHibernateTemplate().find("select taskNo, count(taskNo) from Activity group by taskNo order by taskNo");
}
I would get undefined alias taskNo
which is true because taskNo is not a property of Activity class. taskNo is defined in ActivityPK class which is referenced by Activity class as described in the hbm.xml file
My question is how would I query against a Hibernate Object with composite id with the above sql statement?
Here are the java objects for the tables:
public class Userlog implements Serializable {
/** identifier field */
private com.test.model.UserlogPK comp_id;
/** persistent field */
private Set activites;
/** full constructor */
public Userlog(com.test.model.UserlogPK comp_id, Set activities) {
this.comp_id = comp_id;
this.activities = activities;
}
/** default constructor */
public Userlog() {
}
/**
* @hibernate.id
* generator-class="assigned"
*
*/
public com.test.model.UserlogPK getComp_id() {
return this.comp_id;
}
public void setComp_id(com.test.model.UserlogPK comp_id) {
this.comp_id = comp_id;
}
/**
* @hibernate.set
* lazy="true"
* inverse="true"
* cascade="none"
* @hibernate.collection-key
* column="userid"
* @hibernate.collection-key
* column="date"
* @hibernate.collection-one-to-many
* class="com.test.model.Activity"
*
*/
public Set getActivities() {
return this.activities;
}
public void setActivities(Set activities) {
this.activities = activities;
}
public String toString() {
return new ToStringBuilder(this)
.append("comp_id", getComp_id())
.toString();
}
public boolean equals(Object other) {
if ( !(other instanceof Evalog) ) return false;
Evalog castOther = (Evalog) other;
return new EqualsBuilder()
.append(this.getComp_id(), castOther.getComp_id())
.isEquals();
}
public int hashCode() {
return new HashCodeBuilder()
.append(getComp_id())
.toHashCode();
}
}
public class UserlogPK implements Serializable {
/** identifier field */
private Integer userid;
/** identifier field */
private String date;
/** full constructor */
public UserlogPK(Integer userid, String date) {
this.userid = userid;
this.date = date;
}
/** default constructor */
public UserlogPK() {
}
/**
* @hibernate.property
* column="userid"
* length="4"
*
*/
public Integer getUserid() {
return this.userid;
}
public void setUserid(Integer userid) {
this.userid = userid;
}
public String getDate() {
return this.date;
}
public void setDate(String date) {
this.date = date;
}
public String toString() {
return new ToStringBuilder(this)
.append("userid", getUserid())
.append("date", getDate())
.toString();
}
public boolean equals(Object other) {
if ( !(other instanceof UserlogPK) ) return false;
UserlogPK castOther = (UserlogPK) other;
return new EqualsBuilder()
.append(this.getEvaluated(), castOther.getEvaluated())
.append(this.getEvaluator(), castOther.getEvaluator())
.isEquals();
}
public int hashCode() {
return new HashCodeBuilder()
.append(getEvaluated())
.append(getEvaluator())
.toHashCode();
}
}
Activity class:
public class Activity implements Serializable {
/** identifier field */
private com.test.model.ActivityPK comp_id;
/** nullable persistent field */
private com.test.model.Userlog userlog;
/** full constructor */
public Activity(com.test.model.ActivityPK comp_id, com.test.model.Userlog userlog) {
this.comp_id = comp_id;
this.userlog = userlog;
}
/** default constructor */
public Activity() {
}
/** minimal constructor */
public Activity(com.test.model.ActivityPK comp_id) {
this.comp_id = comp_id;
}
/**
* @hibernate.id
* generator-class="assigned"
*
*/
public com.test.model.ActivityPK getComp_id() {
return this.comp_id;
}
public void setComp_id(com.test.model.ActivityPK comp_id) {
this.comp_id = comp_id;
}
/**
* @hibernate.many-to-one
* update="false"
* insert="false"
*
* @hibernate.column
* name="userid"
*
* @hibernate.column
* name="date"
*
*/
public com.test.model.Userlog getEvalog() {
return this.userlog;
}
public void setEvalog(com.test.model.Userlog userlog) {
this.userlog = userlog;
}
public String toString() {
return new ToStringBuilder(this)
.append("comp_id", getComp_id())
.toString();
}
public boolean equals(Object other) {
if ( !(other instanceof Activity) ) return false;
Activity castOther = (Activity) other;
return new EqualsBuilder()
.append(this.getComp_id(), castOther.getComp_id())
.isEquals();
}
public int hashCode() {
return new HashCodeBuilder()
.append(getComp_id())
.toHashCode();
}
}
public class ActivityPK implements Serializable {
/** identifier field */
private Integer userid;
/** identifier field */
private String date;
/** identifier field */
private Integer taskNo;
/** full constructor */
public ActivityPK(Integer userid, Integer date, Integer taskNo) {
this.userid = userid;
this.date = date;
this.taskNo = taskNo;
}
/** default constructor */
public ActivityPK() {
}
/**
* @hibernate.property
* column="date"
* length="4"
*
*/
public Integer getDate() {
return this.date;
}
public void setDate(Integer date) {
this.date = date;
}
/**
* @hibernate.property
* column="userid"
* length="4"
*
*/
public Integer getEvaluated() {
return this.userid;
}
public void setEvaluated(Integer userid) {
this.userid = userid;
}
public Integer getTaskNo() {
return this.taskNo;
}
public void setTaskNo(Integer taskNo) {
this.taskNo = taskNo;
}
public String toString() {
return new ToStringBuilder(this)
.append("userid", getUserid())
.append("date", getDate())
.append("taskNo", getTaskNo())
.toString();
}
public boolean equals(Object other) {
if ( !(other instanceof ActivityPK) ) return false;
ActivityPK castOther = (ActivityPK) other;
return new EqualsBuilder()
.append(this.getUserid(), castOther.getUserid())
.append(this.getDate(), castOther.getDate())
.append(this.getTaskNo(), castOther.getTaskNo())
.isEquals();
}
public int hashCode() {
return new HashCodeBuilder()
.append(getUserid())
.append(getDate())
.append(getTaskNo())
.toHashCode();
}
}
|