What is the exception?
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);