[jboss-user] [EJB3] - returned values are empty!

Joseph Hwang do-not-reply at jboss.com
Sat Aug 20 02:16:50 EDT 2011


Joseph Hwang [http://community.jboss.org/people/aupres] created the discussion

"returned values are empty!"

To view the discussion, visit: http://community.jboss.org/message/621968#621968

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

- Members.java

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

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

    @Column(name="EMP_Record")
    @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
@Entity
@Table(name = "info")
public class Records implements Serializable {
    
   @Id
   @GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name = "EMP_ID")
    private int i;
    
    @ManyToOne(fetch=FetchType.EAGER, cascade=CascadeType.ALL)
    @JoinColumn(name="EMP_Record")
    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

@Stateless
public class MappingTestBean implements IMappingTestPort {
 
    @PersistenceContext(unitName="MyFamily")
    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*
        System.out.println(records.toString());
  
        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.
--------------------------------------------------------------

Reply to this message by going to Community
[http://community.jboss.org/message/621968#621968]

Start a new discussion in EJB3 at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2029]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20110820/be5dbf79/attachment-0001.html 


More information about the jboss-user mailing list