Hibernate version: WHat comes with JBoss 4.2.2GA
Code
I have a entity that contains a collection of a second entity. The mapping is OneToMany, however I had no way to populate the collection and it is always empty. EAGER fetch won't work, I guess because of this Hibernate open bug HHH-2862. Please help me to figure out how to get the list populated.
First entity - the one owning the collection:
Code:
package org.jboss.tutorial.entity.bean;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.SequenceGenerator;
import javax.persistence.Id;
import javax.persistence.Column;
import javax.persistence.Table;
import javax.persistence.OneToOne;
import javax.persistence.OneToMany;
import javax.persistence.CascadeType;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import java.util.*;
@Entity
@Table(name = "dpac_relt", schema = "dcs3000")
public class DpacRelt implements java.io.Serializable
{
@Id
@Column(name = "bitm_numb_parn")
private int parent;
@Column(name = "bitm_numb_chld")
private int child;
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "bitm_numb", referencedColumnName = "bitm_numb_chld", unique = true)
private List<Sos> sos;
public int getParent()
{
return parent;
}
public void setParent(int parent)
{
this.parent = parent;
}
public int getChild()
{
return child;
}
public void setChild(int child)
{
this.child = child;
}
public List<Sos> getSos()
{
return sos;
}
public void List(List<Sos> sos)
{
this.sos = sos;
}
}
Second entity, the one goes into the collection:Code:
package org.jboss.tutorial.entity.bean;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.SequenceGenerator;
import javax.persistence.Id;
import javax.persistence.Column;
import javax.persistence.Table;
import javax.persistence.ManyToOne;
import javax.persistence.CascadeType;
import javax.persistence.JoinColumn;
@Entity
@Table(name = "sos", schema = "dcs3000")
public class Sos
{
@Id
@Column(name = "sos_numb")
private int sosNumber;
@Column(name = "bitm_numb")
private int item;
public int getSosNumber()
{
return sosNumber;
}
public void setSosNumber(int sosNumber)
{
this.sosNumber = sosNumber;
}
public int getItem()
{
return item;
}
public void setItem(int item)
{
this.item = item;
}
}
The code for retrieving:Code:
public List<DpacRelt> getDpacRelt(int item) {
List<DpacRelt> ll
=
manager
.createQuery("SELECT b FROM DpacRelt b, IN(b.sos) s where s.item = :item")
.setParameter("item", new Integer(item))
.getResultList();
return ll;
}
Full stack trace of any exception that occurs:No exception in this case.
Name and version of the database you are using:Oracle 10g
The generated SQL (show_sql=true):Code:
2008-07-29 12:46:11,014 DEBUG [org.hibernate.SQL] select dpacrelt0_.bitm_numb_parn as bitm1_650_, dpacrelt0_.bitm_numb_chld as bitm2_650_ from dcs3000.dpac_relt dpacrelt0_ inner join dcs3000.sos sos1_ on dpacrelt0_.bitm_numb_chld=sos1_.bitm_numb where sos1_.bitm_numb=?
2008-07-29 12:46:11,061 TRACE [org.hibernate.type.IntegerType] binding '1016' to parameter: 1