Hi ALL,
I'm using jpa,hibernate on mysql. here Im facing one problem. My tables are keyed with auto_increment primary keys. I need to persist one  course object and n branch objects. Code follows ..
Code:
entityManager.persist(course);
for (Branch branch : branchs) {
         if(branch.getTitle()!=null&&!"".equals(branch.getTitle()))
                {
                                branch.setCourse(course);
                                entityManager.persist(branch);
                }
                                 }
But here because of auto_increment id in course table , after persisting
course object is not reflecting it's id. because of this persisting branches failing.
Error is
Code:
13:30:54,812 INFO  [STDOUT] Hibernate: 
    insert 
    into
        engweb1.course
        (duration, title, id) 
    values
        (?, ?, ?)
13:30:54,828 INFO  [STDOUT] Hibernate: 
    insert 
    into
        engweb1.branch
        (title, Course_id, acro, id) 
    values
        (?, ?, ?, ?)
13:30:54,828 WARN  [JDBCExceptionReporter] SQL Error: 1452, SQLState: 23000
13:30:54,828 ERROR [JDBCExceptionReporter]    message from server: "Cannot add or update a child row: a foreign key constraint fails (`engweb1/branch`, CONSTRAINT `fk_Branch_Course` FOREIGN KEY (`Course_id`) REFERENCES `course` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION)"
13:30:54,828 ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
please help me
thanks
raghu