Hi there,
I'm
testing a small app while trying to learn
Java Persistence . Just a newbie at this...
In my first unit of work I create and persist a ScheduledCourse object like so:
EntityManagerFactory emf = Persistence.createEntityManagerFactory("scholastic");
//First Unit of work
EntityManager em1 = emf.createEntityManager();
EntityTransaction tx1 = em1.getTransaction();
tx1.begin();
...
ScheduledCourse scheduled_course = new ScheduledCourse(...);
...
em1.persist(scheduled_course);
...
tx1.commit();
em1.close();
emf.close();
Up to this point everything is fine.
In my second unit of work I try to remove the instance of that object from the database:
EntityManagerFactory emf2 = Persistence.createEntityManagerFactory("scholastic");
EntityManager em2 = emf2.createEntityManager();
EntityTransaction tx2 = em2.getTransaction();
tx2.begin();
...
//Retrieve the entity instance from the dbase and make it persistent again
ScheduledCourse sc = em2.find(ScheduledCourse.class, new Long(1));
...
em2.remove(sc);
...
tx2.commit();
em2.close();
emf2.close();
When the delete is attempted, I get this error message:
[java] Could not synchronize database state with session
[java] org.hibernate.exception.GenericJDBCException: Could not execute
JDBC batch update
Could someone please explain what I may have done wrong? Why isn't the deletion occurring properly?
Alan