This content has been marked as final.
Show 2 replies
-
1. Re: Entitymanager Persistent
fhh May 3, 2007 12:28 PM (in response to poyge394)What is the exception?
Regards
Felix -
2. Re: Entitymanager Persistent
alrubinger May 3, 2007 3:43 PM (in response to poyge394)Well, unless the relationship defined is annotated with @Cascade (CascadeType.PERSIST), you can't persist one entity and expect the relationship to be inserted as well.
So that's one solution.
However, I typically keep the Cascading strategies to NONE as a default (to keep close tabs on what operations the container might do without my explictly telling it so; this is a perference only), and would do the following:// Create Rollingstock rollingstock = new Rollingstock(); rollingstock.setNextRoute( "STH" ); rollingstock.setRoute( "HALL" ); // Create Schedule schedule = new Schedule(); // Persist Each manager.persist(rollingstock); manager.persist(scheulde); // Associate (bi-directionally) after Persisted rollingstock.setSchedule(schedule); schedule.setRollingstock(rollingstock);