Okay, first let me apologize for such a basic question.....but I am so new I am at a lost on how to fix this simple issue.....
What I have done is created a MYSQL database with all the relationships. There are 3 Xref tables (Many to Many). One table uses a composite for the primary key. All the other tables are very simple relationships. I have used MyEclipse to reverse engineer the source code for Hibernate and Spring (DAOs). I corrected all the Spring errors and now I am onto the Hibernate error. I have updated the hbm.xml file adding the cascade styles for each class and changed the generator for each primary key to native. That's all the changes for the hbm.xl files
I made the first trial as simple as possible by only persisting one object with NO relationships (empty HashSet). However, I am getting this error:
When I go looking at the Hibernate source code, I see this information concerning Hibernate's OnLockVisitor
As you can see for yourself this situation occurs if your collection is not a PersistentCollection (i.e. if you have replaced the collection completely after obtaining the object from the DB) or is you use array (not very likely). Because I have not replaced or created any collections, I am at a lost on how this could be...
I must apologize, I do not use Spring, so I am not familiar with their framework.
for persist I usually have code like the following
Session session = sessionFactory.getSession(); Transaction t = session.beginTransaction(); MyObject m = new MyObject(blah blah blah, set up data); session.saveOrUpdate(m); t.commit()
All within a try-catch-finally where I clean up. Now with JPA the code is a little simpler with the EntityManager being injected, and if I was using EJB3 Stateless Sessio bean then I would just have
SOme transaction annotation then
Not that that really helps.
Joined: Apr 25, 2005
This is just the information I need.......
The tool I am using (MyEclipse) generates all the code for the DAOs. The DocumentDAO extends the HibernateSupportDAO. It handles most of the required method generation.
From your comment I can tell you are using the JDBC Template. I changed my code to use something very similar. The SQL generated call for UPDATE of the table. It return zero because no record was in the database with the id of 1. Actually the table is empty. When I tried the save function the SQL generated was an INSERT statement. In both cases no data was stored in the database.
The lock method obtains the specific lock level upon the given object, implicitly checking whether the corresponding database entry still exist. In my case, the lock mode is none. The database is empty so there is no corresponding database entry.
As far as JPA is concerned......It's a hard locked into Spring and Hibernate.