EJB entity relations onetomany
Using @OneToMany and @ManyToOne entity relationship might sound little difficult and confusing in the beginning but actually it is very easy. I recently used it in one of my projects and it worked great.
Here is how the code in your entities should look like...
Assuming table 1 and table 2 have one to many relationship...then...
in the table 1 entity...you have...
... @OneToMany(mappedBy="table2mapping") private Collectiontable2list; ..associated getter and setter...
in the table2 entity..you have...
@JoinColumn(name = "table2ID", referencedColumnName = "table1ID", insertable=false, updatable=false) @ManyToOne private table1 table2mapping;
@JoinColumn should be changed depending upon your requirements...
Let me know if you have any questions...
0 comments:
Post a Comment