1 Reply Latest reply on Aug 26, 2011 8:51 AM by Wolfgang Knauf

    returned values are empty!

    Joseph Hwang Novice

      I coded 2 entity class and joined them with @ManyToOne annotation like below


      - Members.java


      @Table(name = "family")
      public class Members implements Serializable {
          @Column(name = "EMP_ID")
          private String id ;


         @Column(name = "EMP_Passwd")
          private String passwd ;
          @Column(name = "EMP_Name")
          private String name ;


          @OneToMany(fetch=FetchType.EAGER, mappedBy="member", cascade=CascadeType.ALL)
          private List<Records> record;


          ...getter and setter method...



          public List<Records> getRecord() {
             return record;


          public void setRecord(List<Records> record) {
             this.record = record;



      - Records.java

      @Table(name = "info")
      public class Records implements Serializable {
          @Column(name = "EMP_ID")
          private int i;
          @ManyToOne(fetch=FetchType.EAGER, cascade=CascadeType.ALL)
          private Members member;


         @Column(name = "EMP_Bank_Account")
          private String account;


         @Column(name = "EMP_Hobby")
          private String hobby;


          @Column(name = "EMP_Phone")
          private int phone;


          ...getter and setter method..



      EntityManager.persist is OK. Data were inserted well. But Members.getRecord() method is problem.


      In Bean class I coded to return value List<Records> like below


      public class MappingTestBean implements IMappingTestPort {

          EntityManager em;


          public List<Records> getFamilyMember(String name) {
              // TODO Auto-generated method stub
              Members m = (Members)em.find(Members.class, name); // EntityManager.find() works well
              System.out.println(m.toString()); // The method prints some value
              List<Records> records = m.getRecord(); // getRecord() return empty value
              return records;




      in console

      Joined select is executed well.

      [STDOUT] Hibernate: select members0_.EMP_ID as EMP1_49_1_, members0_.EMP_Name as EMP2_49_1_, members0_.EMP_Passwd as EMP3_49_1_, record1_.EMP_Record as EMP5_3_, record1_.EMP_ID as EMP1_3_, record1_.EMP_ID as EMP1_50_0_, record1_.EMP_Bank_Account as EMP2_50_0_, record1_.EMP_Hobby as EMP3_50_0_, record1_.EMP_Record as EMP5_50_0_, record1_.EMP_Phone as EMP4_50_0_ from family members0_ left outer join info record1_ on members0_.EMP_ID=record1_.EMP_Record where members0_.EMP_ID=?


      But records value is empty nor null.


      I need your advice! Thanks in advance.