Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Object Relational Mapping
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Liutauras Vilda
Ron McLeod
Jeanne Boyarsky
Paul Clapham
Sheriffs:
Junilu Lacar
Tim Cooke
Saloon Keepers:
Carey Brown
Stephan van Hulst
Tim Holloway
Peter Rooke
Himai Minh
Bartenders:
Piet Souris
Mikalai Zaikin
Forum:
Object Relational Mapping
[JPA, eclipselink]OneToMany Relationship not working
Jhon Gonzales
Greenhorn
Posts: 22
I like...
posted 9 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hello, i have a problem with an OneToMany relationship. I try to get the List but it does not return anything. Theses are my sources:
This the Main:
public class ModelTest { /** * @param args */ public static void main(String[] args) { //Creating { StudyEntity st = new StudyEntity(); st.setPatientName("Edwin"); st.setStudy_pk("111"); new StudyCRUD().create(st); StudyEntity st2 = new StudyEntity(); st2.setPatientName("Jose"); st2.setStudy_pk("2333"); new StudyCRUD().create(st2); // Persist the object in DB SeriesEntity se = new SeriesEntity(); se.setStudyentity(st); new SeriesCRUD().create(se); SeriesEntity se2 = new SeriesEntity(); se2.setStudyentity(st); new SeriesCRUD().create(se2); // Persist the object in DB } //Retrieving { StudyEntity study = new SeriesCRUD().getStudyEntityByID(1); // Get a Object by ID System.out.println("Name: "+study.getPatientName()); System.out.println("Size: "+study.getStudySeries().size()); } } }
Result:
Name: Edwin
Size: 0
Tables info:
studyentity ida, DELETED, MODALITY, PATIENTNAME, SENT, STUDY_DATETIME, STUDY_ID, STUDY_PK 1, 0, '', 'Edwin', 0, '', '', '111' 2, 0, '', 'Jose', 0, '', '', '2333' seriesentity ID, SERIES_IUID, SERIES_PK, ida 1, '', '', 1 2, '', '', 1
The entities tables:
@Entity @Table(name="studyentity") public class StudyEntity implements Serializable{ @Id @GeneratedValue(strategy=GenerationType.IDENTITY) @Column(name="ida") private long id; private String patientName; private String study_id; private String modality; @Column(unique=true ) private String study_pk; @Temporal(javax.persistence.TemporalType.TIMESTAMP) private Date study_datetime; private boolean sent; @Column(columnDefinition="boolean default false") private boolean deleted; @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY,mappedBy="studyentity") private List<SeriesEntity> studySeries; //getters and setters
@Entity @Table(name="seriesentity") public class SeriesEntity implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy=GenerationType.IDENTITY) private Long id; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "ida", nullable = false) private StudyEntity studyentity; private String series_pk; private String series_iuid; //Getters and Setters
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
?
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
deleting causes : not-null property references a null or transient value
Cascade Type problem
JPA - need help with query
Saving OneToMany , foreign key not set
Edit primary key, if it's a foreign key
More...