I'm using jboss 4.04ga, java 1.5.0_06, postgres 8.0.3, etc.  When trying to 
create Many* relationships I find the foreign keys are somehow not being 
stored.  The rest of the fields of the entities are persisted fine, but the 
relationships do not seem to be.  Strangely, OneToOne relationships seem to 
turn out as expected.  I suspect that I have misconfigured jboss somehow.  in 
my example code, table test1 has one entry, field = 1, test2 has two entries, 
just as expected, only null fk_test1 fields.  My entities are at the bottom of 
this post, I create and persist them as so:
        Test1 t1=new Test1();
        ArrayList<Test2> a=new ArrayList<Test2>();
        Test2 t2=new Test2();
        t2.setField(1);
        a.add(t2);
        t2=new Test2();
        t2.setField(2);
        a.add(t2);
        t1.setTest2s(a);
        t1.setField(1);
        entityManager.persist(t1);
/*
 * Test1.java
 */
// package name intentionally obscured
package entity;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Transient;

@Entity
public class Test1 implements Serializable {
    
    @Transient
    private static final long serialVersionUID = 563564566867744L;
    
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private long id;

    private int field;

    @OneToMany(mappedBy="test1",cascade={CascadeType.ALL})
    private Collection<Test2> test2s;

    public Collection<Test2> getTest2s() {
        return test2s;
    }

    public void setTest2s(Collection<Test2> test2s) {
        this.test2s = test2s;
    }

    public int getField() {
        return field;
    }

    public void setField(int field) {
        this.field = field;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }
}

/*
 * Test2.java
 */

package entity;

import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Transient;

@Entity
public class Test2 implements Serializable {
    
    @Transient
    private static final long serialVersionUID = 7894561357L;
    
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private long id;
    
    private int field;
    
    @ManyToOne
    @JoinColumn(name="fk_test1")
    private Test1 test1;
    
    public Test1 getTest1() {
        return test1;
    }
    
    public void setTest1(Test1 t1) {
        test1=t1;
    }

    public int getField() {
        return field;
    }

    public void setField(int field) {
        this.field = field;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }
}



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

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


-------------------------------------------------------------------------
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
JBoss-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to