-->
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.  [ 1 post ] 
Author Message
 Post subject: How to fetch OneToMany lazy fetch
PostPosted: Tue Jul 29, 2008 3:48 pm 
Newbie

Joined: Mon Jun 16, 2008 1:15 pm
Posts: 15
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.