openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From CarpathianAnonymous <andreibratu2...@yahoo.com>
Subject "element" column of the associated table is null
Date Wed, 25 Apr 2012 10:20:37 GMT
I have an Interface (IInterface) and 2 classes that implements that interface
(IInterface). Also in another class ( Holder ) I have a collection of
interface items ( Collection<IInterface> ). 

When I try to execute the code from OpenJPA_Test.main, in my associated
table ( holder_classes), the column which is supposed to hold the references
to Class1 or Class2 objects are NULL. 

public class OpenJPA_Test { 

    private static HolderDao holderDao =
EntityDaoFactory.inst().getHolderDao(); 
    
    /** 
     * @param args the command line arguments 
     */ 
    public static void main(String[] args) { 
        // TODO code application logic here 
        Holder h = new Holder(); 
        LinkedList<IInterface> list = new LinkedList<IInterface>(); 
        
        Class1 c1 = new Class1(); 
        Class2 c2 = new Class2(); 
        
        list.add(c1); 
        list.add(c2); 
        
        h.setClasses(list); 
        holderDao.create(h); 
        
    } 
} 


@ManagedInterface 
public interface IInterface { 
    @Id 
    @GeneratedValue(strategy = GenerationType.IDENTITY) 
    int getId(); 
    void setId(int id); 
} 


@Entity 
@Table(name = "class1") 
public class Class1 implements IInterface { 

    @Id 
    private int id; 
    @Basic 
    private int number; 

    public Class1() { 
    } 

    @Override 
    public int getId() { 
        return id; 
    } 

    @Override 
    public void setId(int id) { 
        this.id = id; 
    } 

    public int getNumber() { 
        return number; 
    } 

    public void setNumber(int number) { 
        this.number = number; 
    } 
} 



@Entity 
@Table(name = "class2") 
public class Class2 implements IInterface { 

    @Id 
    private int id; 
    @Basic 
    private String text; 
    
    public Class2(){ 
    } 

    public String getText() { 
        return text; 
    } 

    public void setText(String text) { 
        this.text = text; 
    } 

    public int getId() { 
        return id; 
    } 

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



@Entity 
@Table(name = "holder") 
public class Holder { 

    @Id 
    @GeneratedValue(strategy = GenerationType.IDENTITY) 
    private int id; 
    @OneToMany(cascade = CascadeType.ALL) 
    private Collection<IInterface> classes; 
    
    public Holder(){ 
    } 

    public Collection<IInterface> getClasses() { 
        return classes; 
    } 

    public void setClasses(Collection<IInterface> classes) { 
        this.classes = classes; 
    } 

    public int getId() { 
        return id; 
    } 

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

--
View this message in context: http://openjpa.208410.n2.nabble.com/element-column-of-the-associated-table-is-null-tp7498933p7498933.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Mime
View raw message