I have two beans A and B

package au.com.pulse.online.persistence.ejb.crm;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@javax.persistence.Entity
@Table(name = "A")
public class A {
    
    private long col1;
    private String col2;
    private String col3;
    private List bvals;
    
    @Id()
    @GeneratedValue( strategy=GenerationType.AUTO )
    @Column(name = "COL_1")
    public long getCol1() {
        return col1;
    }
    public void setCol1(long col1) {
        this.col1 = col1;
    }
    
    @Column(name = "COL_2")
    public String getCol2() {
        return col2;
    }
    public void setCol2(String col2) {
        this.col2 = col2;
    }
    
    @Column(name = "COL_3")
    public String getCol3() {
        return col3;
    }
    public void setCol3(String col3) {
        this.col3 = col3;
    }
    
    @OneToMany(fetch = FetchType.LAZY)
    @Column(name="COL_1")
    @JoinColumn(name="COL_2")
    public List getBs() {
        return bvals;
    }
    
    public void setBs(List bvals) {
        this.bvals = bvals;
    }
}

package au.com.pulse.online.persistence.ejb.crm;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@javax.persistence.Entity
@Table(name = "B")
public class B {
    private long col1;
    private long col2;
    private String col3;
    
    @Id()
    @GeneratedValue( strategy=GenerationType.AUTO )
    @Column(name = "COL_1")
    public long getCol1() {
        return col1;
    }
    public void setCol1(long col1) {
        this.col1 = col1;
    }
    
    @Column(name = "COL_2")
    public long getCol2() {
        return col2;
    }
    public void setCol2(long col2) {
        this.col2 = col2;
    }
    
    @Column(name = "COL_3")
    public String getCol3() {
        return col3;
    }
    public void setCol3(String col3) {
        this.col3 = col3;
    }
    
    
}


And a session bean that has the following method:

    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public A getA() {
        try {
            A a = (A) em.createQuery("from A where col1 = 1").getSingleResult();
            List bs = a.getBs();
            return a;
        } catch (Exception e) {
            log.info(e);
            return null;
        }       
    }

If I define the following:

@OneToMany(fetch = FetchType.EAGER) 

then the list of B's gets populated when the query runs. If I leave it as LAZY 
then it never gets populated. Does anybody know what I'm missing here?

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3939098#3939098

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3939098


-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to