Guys, i used hibernate 2.1.1 in the project.
here is the code and the mapping
Code:
class PlanItem {
//...there are some other properties and getters/setters
private List loggedDataList;
public List getLoggedDataList() {return this.loggedDataList;}
public void setLoggedDataList(list) {this.loggedDataList = list;}
}
class NoticeItem {
//...there are some other properties and getters/setters
private List loggedDataList;
public List getLoggedDataList() {return this.loggedDataList;}
public void setLoggedDataList(list) {this.loggedDataList = list;}
}
class LoggedData {
private String loggedDataId;
private Date logDateTime;
private DateSpan dateSpan;
private Integer quantity;
private Integer loggedDataSeqId;
private Object referencedEntity;
public DateSpan getDateSpan() {
return dateSpan;
}
public void setDateSpan(DateSpan dateSpan) {
this.dateSpan = dateSpan;
}
public String getLoggedDataId() {
return loggedDataId;
}
public void setLoggedDataId(String loggedDataId) {
this.loggedDataId = loggedDataId;
}
public Integer getQuantity() {
return quantity;
}
public void setQuantity(Integer quantity) {
this.quantity = quantity;
}
/**
* @return Returns the loggedDataSeqId.
*/
public Integer getLoggedDataSeqId() {
return loggedDataSeqId;
}
/**
* @param loggedDataSeqId The loggedDataSeqId to set.
*/
public void setLoggedDataSeqId(Integer loggedDataSeqId) {
this.loggedDataSeqId = loggedDataSeqId;
}
public Object getReferencedEntity() {
return this.referencedEntity;
}
public void setReferencedEntity(Object referencedEntity) {
this.referencedEntity = referencedEntity;
}
public Date getLogDateTime() {
return this.logDateTime;
}
public void setLogDateTime(Date logDateTime) {
this.logDateTime = logDateTime;
}
}
<class name="eg.PlanItem" table="PLAN_ITEM" dynamic-update="false" lazy="true">
<!--some properties-->
<list name="loggedDataList" lazy="true" inverse="true" cascade="all" outer-join="false">
<key column="REFERENCED_ID"/>
<index column="LOGGED_DATA_SEQ_ID"/>
<one-to-many class="eg.LoggedData"></one-to-many>
</list>
</class>
<class name="eg.NoticeItem" table="NOTICE_ITEM" dynamic-update="false" lazy="true">
<!--some properties-->
<list name="loggedDataList" lazy="true" inverse="true" cascade="all" outer-join="false">
<key column="REFERENCED_ID"/>
<index column="LOGGED_DATA_SEQ_ID"/>
<one-to-many class="eg.LoggedData"/>
</list>
</class>
<class name="eg.LoggedData" table="LOGGED_DATA" dynamic-update="false" lazy="true">
<id name="loggedDataId" column="LOGGED_DATA_ID" type="string" length="20" unsaved-value="any">
<generator class="native"/>
</id>
<property name="loggedDataSeqId" column="LOGGED_DATA_SEQ_ID" type="integer" />
<property name="logDateTime" type="timestamp" column="LOG_DATE_TIME" insert="true" update="true"/>
<component name="dateSpan" class="eg.DateSpan">
<many-to-one name="dateSpanType" class="eg.DateSpanTypeEntity" cascade="none" outer-join="false" update="true" insert="true" column="DATE_SPAN_TYPE_ID"/>
<property name="dateTimeFrom" type="timestamp" update="true" insert="true" column="DATE_TIME_FROM"/>
<property name="dateTimeTo" type="timestamp" update="true" insert="true" column="DATE_TIME_TO"/>
</component>
<property name="quantity" type="java.lang.Integer" update="true" insert="true" column="QUANTITY"/>
<any id-type="string" name="referencedEntity">
<column name="REFERENCED_CLASS"/>
<column name="REFERENCED_ID"/>
</any>
</class>
Then, suppose we have one record of PlanItem which id is "1" and another record of NoticeItem which id has the same value of "1", and there are varies entity records of LoggedData class for each one 'Item', then everytime i called the method getLoggedDataList in PlanItem class, the LoggedData records which related with the NoticeItem will be fetched too.
How can i get the correct list of loggedData?