This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Whats wrong with the code ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Whats wrong with the code ?" Watch "Whats wrong with the code ?" New topic

Whats wrong with the code ?

Nikhil Jain
Ranch Hand

Joined: May 15, 2005
Posts: 385

What is the problem with the above code? The enties works well when I try to persist them in isolation. I am trying to persister these objects in a single trasaction.

There is no problem with the database, as it works well when executed by persisting the objects one by one ...

SCJP 1.4, SCWCD 1.4, SCBCD 1.5
Mike Keith
Ranch Hand

Joined: Jul 14, 2005
Posts: 304
1) Bad karma to access the EM from within the entity class.

2) Your relationship is not properly mapped. Try this:

3. You should probably set the id in employee to not be generated so you can assign it when you create one and then use the assigned id value to find it later on. Otherwise you won't know what id value got assigned to the employee unless you hold on to it, etc.

Pro JPA 2: Mastering the Java Persistence API
I agree. Here's the link:
subject: Whats wrong with the code ?
Similar Threads
persistence.xml file for MS SQL Server 2000
Problem in composite key mapping in eclipselink
Problem with refresh() method of EntityManamger in JPA
Hibernate SaveOrUpdate
Problem with @Column annotation or corresponding xml tag if used with @Id annotation