-->
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.  [ 4 posts ] 
Author Message
 Post subject: Compisit-ID returning the same data in every row.
PostPosted: Wed Nov 24, 2004 11:27 am 
Beginner
Beginner

Joined: Wed Nov 24, 2004 10:54 am
Posts: 48
This is my first try with Composit keys. I am workoing with a legacy database and for this table, the fields OBDATE, OBKEYNBR, and OBSEQ make up a unque key.

When I loop through the list, every item has the same data? It is always the first item in the record set. Am I missing something?

My hbm.xml file...

<class name="com.sys.dao.LabobrBean" table="LABOBR">
<composite-id name="labobrKey" class="com.sys.dao.LabobrComposite">
<key-property name="labTestDate" column="OBDATE"/>
<key-property name="seqNo" column="OBKEYNBR"/>
<key-property name="resultsProcessingSeqNo" column="OBSEQ"/>

</composite-id>

... other mappings ....

My composite class.

public class LabobrComposite implements java.io.Serializable {

private String labobrKey = null;
private Integer labTestDate = null;
private Integer seqNo = null;
private Integer resultsProcessingSeqNo = null;

public String getLabobrKey() {
return (this.labobrKey);
}
public void setLabobrKey(String labobrKey) {
this.labobrKey = labobrKey;
}
public Integer getLabTestDate() {
return (this.labTestDate);
}
public void setLabTestDate(Integer labTestDate) {
this.labTestDate = labTestDate;
}
public Integer getSeqNo() {
return (this.seqNo);
}
public void setSeqNo(Integer seqNo) {
this.seqNo = seqNo;
}
public Integer getResultsProcessingSeqNo() {
return (this.resultsProcessingSeqNo);
}
public void setResultsProcessingSeqNo(Integer resultsProcessingSeqNo) {
this.resultsProcessingSeqNo = resultsProcessingSeqNo;
}
public boolean equals(Object other){
if(!(other instanceof LabobrComposite)) return false;
LabobrComposite castOther = (LabobrComposite) other;
return new EqualsBuilder().append(this.getLabobrKey(),
castOther.getLabobrKey()).isEquals();
}
public int hashCode(){
return new HashCodeBuilder().append(getLabobrKey()).toHashCode();
}
}

When I look at the log, it shows that two rows have been returned (sorry can not show you. It contains patient data). However, the list has the same data for each row.

Any help?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 24, 2004 2:13 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
bad hashcode equals

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 24, 2004 3:26 pm 
Beginner
Beginner

Joined: Wed Nov 24, 2004 10:54 am
Posts: 48
Thanks! I took out the EqualsBuilder and HashCodeBuilder and replaced it with an example I found in this forum. All is working now.

Thanks again!


Top
 Profile  
 
 Post subject: Composite-id key properties not recognized in createSQLQuery
PostPosted: Fri Dec 03, 2004 4:57 pm 
Newbie

Joined: Fri Dec 03, 2004 4:41 pm
Posts: 15
I'm using a create SQL query that maps to a class with composite primary keys mapping to a oracle 9i database. I need it to call a max function on a particular column that's one of the composite ids.

I keep getting the error net.sf.hibernate.QueryException: No column name found for property [partyId] though my find functions work great and it doesn't give a error on the regular property elements. Is there a way to map to composite ids using this call?

ex:
createSQLQuery("select {pad}.test as {pad.test}, max({pad}.prty_id) as {pad.partyId} " +
"from MYTABLE {pad}",
"pad", MyClass.class)

mapping ex:

<class name="MyClass" table="MYTABLE">

<composite-id name="pk" class="MyPrimaryKey">
<key-property name="partyId" column="PRTY_ID" type="java.math.BigDecimal" />
</composite-id>
<property name="test" column="modified_by" />
</class>


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