-->
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.  [ 3 posts ] 
Author Message
 Post subject: Issue retrieving Child Objects using OneToMany Annotation
PostPosted: Fri Jun 29, 2012 8:28 am 
Newbie

Joined: Fri Jun 29, 2012 7:59 am
Posts: 3
Hi Everyone,
Many days I have been looking through many forums to clarify my doubts but never posted a query. This is my first introduction to a forum. Please help me in solving the below issue.

Following are the table structure

CREATE TABLE CU_LOOKUP_LIST (
LOOKUP_LIST_ID CHAR(20) NOT NULL,
COUNTRY_CD CHAR(2) NOT NULL,
LIST_TYPE_CD VARCHAR(7) NOT NULL,
LIST_DSC VARCHAR(50) NOT NULL,
CREATED_USR_ID CHAR(7) NOT NULL,
CREATED_DTE TIMESTAMP NOT NULL,
MOIDIFIED_USR_ID CHAR(7) ,
MODIFIED_DTE TIMESTAMP
);

CREATE TABLE CU_LOOKUP_LIST_VALUE (
LIST_ID CHAR(9) NOT NULL,
LOOKUP_KEY VARCHAR(50) NOT NULL,
LOOKUP_VALUE VARCHAR(160) NOT NULL,
DATA_ELEMNT_NAM VARCHAR(50) NOT NULL,
ENV_NAM VARCHAR(10) NOT NULL,
COUNTRY_CD CHAR(2) NOT NULL,
CREATED_USR_ID CHAR(7) NOT NULL,
CREATED_DTE TIMESTAPM NOT NULL,
MODIFIED_USE_ID CHAR(7) ,
MODIFIED_DTE TIMESTAMP
);
Note: One LookupList has multiple LookupListValue entries.
Following are the entity mappings
CU_LOOKUP_LIST:
@Id
@GeneratedValue
@Column(name="LOOKUP_LIST_ID", unique= true, nullable=false, length=9)
public String getLookupListId() {
return this.lookupListId;
}

public void setLookupListId(String lookupListId) {
this.lookupListId = lookupListId;
}

@Column(name="COUNTRY_CD", nullable=false, length=2)
public String getCountryCd() {
return this.countryCd;
}

public void setCountryCd(String countryCd) {
this.countryCd = countryCd;
}

@Column(name="CREATED_DTE", nullable=false)
public Date getCreatedDte() {
return this.createdDte;
}

public void setCreatedDte(Date createdDte) {
this.createdDte = createdDte;
}

@Column(name="CREATED_USR_ID", nullable=false, length=7)
public String getCreatedUsrId() {
return this.createdUsrId;
}

public void setCreatedUsrId(String createdUsrId) {
this.createdUsrId = createdUsrId;
}


@Column(name="LIST_DSC", nullable=false, length=50)
public String getListDsc() {
return this.listDsc;
}

public void setListDsc(String listDsc) {
this.listDsc = listDsc;
}


@Column(name="LIST_TYPE_CD", nullable=false, length=7)
public String getListTypeCd() {
return this.listTypeCd;
}

public void setListTypeCd(String listTypeCd) {
this.listTypeCd = listTypeCd;
}


@Column(name="MODIFIED_DTE")
public Date getModifiedDte() {
return this.modifiedDte;
}

public void setModifiedDte(Date modifiedDte) {
this.modifiedDte = modifiedDte;
}

@Column(name="MODIFIED_USR_ID", length=7)
public String getMoidifiedUsrId() {
return this.modifiedUsrId;
}

public void setMoidifiedUsrId(String moidifiedUsrId) {
this.modifiedUsrId = moidifiedUsrId;
}


@OneToMany(fetch=FetchType.EAGER, mappedBy="cuLookupList", cascade=CascadeType.ALL)
public Set<CuLookupListValue> getCuLookupListValue() {
return this.cuLookupListValue;
}

public void setCuLookupListValue(Set<CuLookupListValue> cuLookupListValue) {
this.cuLookupListValue = cuLookupListValue;
}

CU_LOOKUP_LIST_VALUE:
@Id
@GeneratedValue
@Column(name="LIST_ID", unique=false, nullable=false)
public String getLookupListId(){
return this.lookupListId;
}

public void setLookupListId(String lookupListId){
this.lookupListId = lookupListId;
}
@Column(name="COUNTRY_CD", nullable=false, length=2)
public String getCountryCd() {
return this.countryCd;
}

public void setCountryCd(String countryCd) {
this.countryCd = countryCd;
}

@Column(name="CREATED_DTE", nullable=false)
public Date getCreatedDte() {
return this.createdDte;
}

public void setCreatedDte(Date createdDte) {
this.createdDte = createdDte;
}

@Column(name="CREATED_USR_ID", nullable=false, length=7)
public String getCreatedUsrId() {
return this.createdUsrId;
}

public void setCreatedUsrId(String createdUsrId) {
this.createdUsrId = createdUsrId;
}

@Column(name="DATA_ELEMNT_NAM", nullable=false, length=50)
public String getDataElemntNam() {
return this.dataElemntNam;
}

public void setDataElemntNam(String dataElemntNam) {
this.dataElemntNam = dataElemntNam;
}

@Column(name="ENV_NAM", nullable=false, length=10)
public String getEnvNam() {
return this.envNam;
}

public void setEnvNam(String envNam) {
this.envNam = envNam;
}

@Column(name="LOOKUP_KEY", nullable=false, length=50)
public String getLookupKey() {
return this.lookupKey;
}

public void setLookupKey(String lookupKey) {
this.lookupKey = lookupKey;
}

@Column(name="LOOKUP_VALUE", nullable=false, length=160)
public String getLookupValue() {
return this.lookupValue;
}

public void setLookupValue(String lookupValue) {
this.lookupValue = lookupValue;
}

@Column(name="MODIFIED_DTE")
public Date getModifiedDte() {
return this.modifiedDte;
}

public void setModifiedDte(Date modifiedDte) {
this.modifiedDte = modifiedDte;
}

@Column(name="MODIFIED_USR_ID", length=7)
public String getModifiedUseId() {
return this.modifiedUseId;
}

public void setModifiedUseId(String modifiedUseId) {
this.modifiedUseId = modifiedUseId;


}


@ManyToOne(cascade=CascadeType.ALL,fetch=FetchType.EAGER)
@JoinColumn(name="LIST_ID", nullable=false, insertable=false, updatable=false)

public CuLookupList getCuLookupList() {
return cuLookupList;
}


public void setCuLookupList(CuLookupList cuLookupList) {
this.cuLookupList = cuLookupList;
}

When hitting the CU_LOOKUP_LIST(Parent Table) with listTypeCd as where condition, Hibernate internally performs to db hits.Following are the HQL Queries

PARENT TABLE QUERY:
select C.LOOKUP_LIST_ID as LOOKUP1_1571_, C.COUNTRY_CD as COUNTRY2_1571_, C.CREATED_DTE as CREATED3_1571_, C.CREATED_USR_ID as CREATED4_1571_, C.LIST_DSC as LIST5_1571_, C.LIST_TYPE_CD as LIST6_1571_, C.MODIFIED_DTE as MODIFIED7_1571_, C.MODIFIED_USR_ID as MODIFIED8_1571_ from ID2XGCUD.CU_LOOKUP_LIST C where C.LIST_TYPE_CD=?

CHILD TABLE QUERY:
select C.LIST_ID as LIST1_1_, C.LIST_ID as LIST1_1572_0_, C.COUNTRY_CD as COUNTRY2_1572_0_, C.CREATED_DTE as CREATED3_1572_0_, C.CREATED_USR_ID as CREATED4_1572_0_, C.DATA_ELEMNT_NAM as DATA5_1572_0_, C.ENV_NAM as ENV6_1572_0_, C.LOOKUP_KEY as LOOKUP7_1572_0_, C.LOOKUP_VALUE as LOOKUP8_1572_0_, C.MODIFIED_DTE as MODIFIED9_1572_0_, C.MODIFIED_USR_ID as MODIFIED10_1572_0_ from ID2XGCUD.CU_LOOKUP_LIST_VALUE C where C.LIST_ID=?

Issue : I have one record in parent table with ID=100 and 2 records in child table with the same id as 100. When hibernate retrieves the records of child table, its a persistentBag with size as 2. But the actual problem here is that, both the 2 objects are of first entry in child table. Duplicate record is present. Please help me in solving this issue. Let me know if I need to be clear anywhere or if any more details are required.


Top
 Profile  
 
 Post subject: Re: Issue retrieving Child Objects using OneToMany Annotation
PostPosted: Sat Jun 30, 2012 2:22 pm 
Newbie

Joined: Fri Jun 29, 2012 7:59 am
Posts: 3
Can anyone please help me out with the issue posted above.....


Top
 Profile  
 
 Post subject: Re: Issue retrieving Child Objects using OneToMany Annotation
PostPosted: Sat Jun 30, 2012 4:59 pm 
Newbie

Joined: Fri Jun 29, 2012 7:59 am
Posts: 3
Any suggestion would be highly appreciated !!!!


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