Hello everyone.
I'm using Hibernate 3.2.6.GA with Hibernate-EntityManager 3.3.1.GA and Hibernate-C3P0 3.3.1.GA (maven deps). Hibernate is hooked up through Spring 2.5. All of my persistent objects are written in JPA with the DAOs written with Spring JPA. The database behind all of this is MySQL 5 and i'm using C3P0 to manage the connection pool.
Here's my scenario. I have two classes; let's call them Model and Brand. I create a new Brand object and persist it to the database. I then create a new Model object and assign the recently persisted Brand object as part of its member variable. In the Model class Brand is linked using the following annotations.
Code:
@OneToOne(cascade = CascadeType.ALL)
@PrimaryKeyJoinColumn
Now when I try to persist the Model object I get the following error from Hibernate.
Code:
org.hibernate.PersistentObjectException: detached entity passed to persist: Brand
Each call to persist occurs within its own transaction as the Dao classes are written as @Transactional. Can anyone explain why this is happening? This is a pretty big problem for me if I can't link classes together.
Thanks in advance