Issue Details (XML | Word | Printable)

Key: NUCJPA-100
Type: Bug Bug
Status: Closed Closed
Resolution: Cannot Reproduce
Priority: Critical Critical
Assignee: Unassigned
Reporter: yuri
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
DataNucleus API JPA

Cannot delete an instance if it has @Version in @MappedSuperclass

Created: 13/Jan/11 09:50 AM   Updated: 27/Jan/11 05:15 PM   Resolved: 13/Jan/11 10:34 AM
Component/s: None
Affects Version/s: 2.1.0.release
Fix Version/s: None

File Attachments: 1. Zip Archive JPATest.zip (3 kB)

Environment: Ubuntu 10.04 64 bit

Forum Thread URL: http://www.datanucleus.org/servlet/forum/viewthread_thread,5910_lastpage,yes
Datastore: PostgreSQL
Severity: Development


 Description  « Hide
When a @Version is declared in @MappedSuperclass, creating an instance succeeds, but deleting fails with an exception:

SEVERE: Object with id "5" in table "jpatest"."B" has no version set on the object in memory and you want to delete it!! Please report this bug to the developers of DataNucleus with a way of reproducing it
Jan 13, 2011 12:29:07 AM org.datanucleus.test.Main main
INFO: >> Exception thrown retrieving objects
javax.persistence.RollbackException: Transaction failed to commit
at org.datanucleus.jpa.EntityTransactionImpl.commit(EntityTransactionImpl.java:120)
at org.datanucleus.test.Main.main(Main.java:44)
Caused by: javax.persistence.PersistenceException: Object with id "5" in table "jpatest"."B" has no version set on the object in memory and you want to delete it!! Please report this bug to the developers of DataNucleus with a way of reproducing it
at org.datanucleus.jpa.NucleusJPAHelper.getJPAExceptionForNucleusException(NucleusJPAHelper.java:287)
at org.datanucleus.jpa.EntityTransactionImpl.commit(EntityTransactionImpl.java:118)
... 1 more
Caused by: org.datanucleus.exceptions.NucleusException: Object with id "5" in table "jpatest"."B" has no version set on the object in memory and you want to delete it!! Please report this bug to the developers of DataNucleus with a way of reproducing it
at org.datanucleus.store.rdbms.request.DeleteRequest.execute(DeleteRequest.java:257)
at org.datanucleus.store.rdbms.RDBMSPersistenceHandler.deleteTable(RDBMSPersistenceHandler.java:532)
at org.datanucleus.store.rdbms.RDBMSPersistenceHandler.deleteObject(RDBMSPersistenceHandler.java:501)
at org.datanucleus.jdo.state.JDOStateManagerImpl.internalDeletePersistent(JDOStateManagerImpl.java:4334)
at org.datanucleus.jdo.state.JDOStateManagerImpl.flush(JDOStateManagerImpl.java:4684)
at org.datanucleus.ObjectManagerImpl.flushInternal(ObjectManagerImpl.java:3156)
at org.datanucleus.ObjectManagerImpl.flush(ObjectManagerImpl.java:3096)
at org.datanucleus.ObjectManagerImpl.preCommit(ObjectManagerImpl.java:3235)
at org.datanucleus.ObjectManagerImpl$2.transactionPreCommit(ObjectManagerImpl.java:316)
at org.datanucleus.TransactionImpl.internalPreCommit(TransactionImpl.java:394)
at org.datanucleus.TransactionImpl.commit(TransactionImpl.java:279)
at org.datanucleus.jpa.EntityTransactionImpl.commit(EntityTransactionImpl.java:106)


Sort Order: Ascending order - Click to sort in descending order
yuri added a comment - 13/Jan/11 09:52 AM
As soon as I move @Version from A to B, the test case starts working.

Please help!

Andy Jefferson added a comment - 13/Jan/11 10:34 AM
I use latest code. I run that test and all executes as expected.
09:33:15,126 (Thread-3) DEBUG [DataNucleus.Datastore.Native] - SELECT 'org.datanucleus.test.B' AS NUCLEUS_TYPE,B.ID AS NUCORDER0,B.VERSION
FROM B B ORDER BY NUCORDER0
09:33:15,127 (Thread-3) DEBUG [DataNucleus.Datastore.Retrieve] - Execution Time = 0 ms
09:33:15,133 (org.datanucleus.test.Main.main()) DEBUG [DataNucleus.Query] - JPQL Query : Execution Time = 11 ms
09:33:15,141 (org.datanucleus.test.Main.main()) DEBUG [DataNucleus.Cache] - Object "org.datanucleus.test.B@1627c16" (id="org.datanucleus.te
st.B:0") taken from Level 1 cache (loadedFlags="[YN]") [cache size = 1]
09:33:15,142 (org.datanucleus.test.Main.main()) DEBUG [DataNucleus.Lifecycle] - Object "org.datanucleus.test.B@1627c16" (id="org.datanucleu
s.test.B:0") has a lifecycle change : "HOLLOW"->"P_NONTRANS"
09:33:15,142 (org.datanucleus.test.Main.main()) INFO [DataNucleus.General] - >> deleting {id: 0, version: 1}
09:33:15,143 (org.datanucleus.test.Main.main()) DEBUG [DataNucleus.Persistence] - Deleting object from persistence : "org.datanucleus.test.B@1627c16"
09:33:15,144 (org.datanucleus.test.Main.main()) DEBUG [DataNucleus.Lifecycle] - Object "org.datanucleus.test.B@1627c16" (id="org.datanucleus.test.B:0") has a lifecycle change : "P_NONTRANS"->"P_DELETED"
09:33:15,145 (org.datanucleus.test.Main.main()) DEBUG [DataNucleus.Transaction] - Object "org.datanucleus.test.B@1627c16" (id="0") enlisted in transactional cache
09:33:15,145 (org.datanucleus.test.Main.main()) DEBUG [DataNucleus.Transaction] - Transaction committing for ObjectManager org.datanucleus.ExecutionContextImpl@c12978
09:33:15,145 (org.datanucleus.test.Main.main()) DEBUG [DataNucleus.Persistence] - ObjectManager internalFlush() process started - 1 dirty objects
09:33:15,150 (org.datanucleus.test.Main.main()) DEBUG [DataNucleus.Persistence] - Object "org.datanucleus.test.B@1627c16" being deleted from table "B"
09:33:15,150 (org.datanucleus.test.Main.main()) DEBUG [DataNucleus.Connection] - Connection found in the pool : [org.datanucleus.store.rdbms.ConnectionFactoryImpl$ManagedConnectionImpl@1214626, jdbc:hsqldb:mem:nucleus, UserName=SA, HSQL Database Engine Driver] for key=org.datanucleus.ExecutionContextImpl@c12978 in factory=ConnectionFactory:tx[org.datanucleus.store.rdbms.ConnectionFactoryImpl@82a13a]
09:33:15,151 (org.datanucleus.test.Main.main()) DEBUG [DataNucleus.Datastore.Retrieve] - Retrieving PreparedStatement for connection "jdbc:hsqldb:mem:nucleus, UserName=SA, HSQL Database Engine Driver"
09:33:15,151 (org.datanucleus.test.Main.main()) DEBUG [DataNucleus.Datastore.Native] - DELETE FROM B WHERE ID=<0> AND VERSION=<1>
09:33:15,151 (org.datanucleus.test.Main.main()) DEBUG [DataNucleus.Datastore.Persist] - Execution Time = 0 ms (number of rows = 1)
09:33:15,152 (org.datanucleus.test.Main.main()) DEBUG [DataNucleus.Datastore.Retrieve] - Closing PreparedStatement org.datanucleus.store.rdbms.ParamLoggingPreparedStatement@10278c5
09:33:15,152 (org.datanucleus.test.Main.main()) DEBUG [DataNucleus.Persistence] - ObjectManager internalFlush() process finished
09:33:15,153 (org.datanucleus.test.Main.main()) DEBUG [DataNucleus.Cache] - Object "org.datanucleus.test.B@1627c16" (id="0") removed from Level 2 cache [cache size = 0]
09:33:15,153 (org.datanucleus.test.Main.main()) DEBUG [DataNucleus.Transaction] - Committing [DataNucleus Transaction, ID=Xid=
, enlisted resources=[org.datanucleus.store.rdbms.ConnectionFactoryImpl$EmulatedXAResource@3fc47c]]

yuri added a comment - 13/Jan/11 06:50 PM
Andy, really appreciate your quick response!

I tried datanucleus-accessplatform-full-deps-2.2.0-release.zip, and I am still seeing the problem.
As soon as I move @Version to the sub-class (from A to B), the problem disappears.

Where can I get the latest code that you checked against to try this out?
Also, what database did you use to reproduce the problem?

Thanks again,
Yuri

Andy Jefferson added a comment - 13/Jan/11 07:38 PM
Where do you get latest code from ? nightly build perhaps, as per the docs

How to run it ? Maven project provided at
http://datanucleus.svn.sourceforge.net/viewvc/datanucleus/test/user.testcase/trunk/

Barring that, go and debug it. If it doesn't have a version set then work out why. Can't be that hard since there are only a handful of SQL invoked.

yuri added a comment - 13/Jan/11 10:55 PM
Andy, thanks for the link and the advice, I might have to do this.

As I said I moved from datanucleus 2.1 release to datanucleus 2.2 release and still was getting the same issue.

Then I moved from PostgreSQL 8.4.6 to PostgreSQL 9.0.2 and from postgresql-jdbc3-8.4.jar to postgresql-9.0-801.jdbc4.jar and it seems the test behaves slightly differently.

When I run the test as it is, it works.

If I comment
// em.remove(b);
then run the test to create an object without deleting it, then uncomment the above line and run the test again, I'm getting the same exception (the trace is below).

The same error happens if I add 2 objects, like below

 em.persist(new B());
 em.persist(new B());

but then delete only one (without any modification to the delete code). The test runs the first time, then it fails on all successive runs.

I will follow your advice on getting the sources to speed this up.

I would also really appreciate it if you could please verify that the test works with your build and with the modifications that I described above.

Thanks again,
Yuri

--------------------------------------------------
INFO: >> Exception thrown retrieving objects
javax.persistence.RollbackException: Transaction failed to commit
at org.datanucleus.jpa.EntityTransactionImpl.commit(EntityTransactionImpl.java:120)
at org.datanucleus.test.Main.main(Main.java:44)
Caused by: javax.persistence.PersistenceException: Object with id "7" in table "jpatest"."B" has no version set on the object in memory and you want to delete it!! Please report this bug to the developers of DataNucleus with a way of reproducing it
at org.datanucleus.jpa.NucleusJPAHelper.getJPAExceptionForNucleusException(NucleusJPAHelper.java:287)
at org.datanucleus.jpa.EntityTransactionImpl.commit(EntityTransactionImpl.java:118)
... 1 more
Caused by: org.datanucleus.exceptions.NucleusException: Object with id "7" in table "jpatest"."B" has no version set on the object in memory and you want to delete it!! Please report this bug to the developers of DataNucleus with a way of reproducing it
at org.datanucleus.store.rdbms.request.DeleteRequest.execute(DeleteRequest.java:291)
at org.datanucleus.store.rdbms.RDBMSPersistenceHandler.deleteTable(RDBMSPersistenceHandler.java:494)
at org.datanucleus.store.rdbms.RDBMSPersistenceHandler.deleteObject(RDBMSPersistenceHandler.java:463)
at org.datanucleus.jdo.state.JDOStateManagerImpl.internalDeletePersistent(JDOStateManagerImpl.java:4448)
at org.datanucleus.jdo.state.JDOStateManagerImpl.flush(JDOStateManagerImpl.java:4798)
at org.datanucleus.ObjectManagerImpl.flushInternal(ObjectManagerImpl.java:3176)
at org.datanucleus.ObjectManagerImpl.flush(ObjectManagerImpl.java:3116)
at org.datanucleus.ObjectManagerImpl.preCommit(ObjectManagerImpl.java:3257)
at org.datanucleus.ObjectManagerImpl$2.transactionPreCommit(ObjectManagerImpl.java:322)
at org.datanucleus.TransactionImpl.internalPreCommit(TransactionImpl.java:394)
at org.datanucleus.TransactionImpl.commit(TransactionImpl.java:279)
at org.datanucleus.jpa.EntityTransactionImpl.commit(EntityTransactionImpl.java:106)
... 1 more

--------------------------------------------------

yuri added a comment - 13/Jan/11 10:58 PM
Andy, for your convenience, the below code fails for me on the second run:

Thank you,
Yuri

--------------------------------------------------------------------
public class Main {
static public void main(String[] args) {
final EntityManagerFactory emf = Persistence.createEntityManagerFactory("JPATest", null);

final EntityManager em = emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
try {
tx.begin();

em.persist(new B());
em.persist(new B());

tx.commit();
} catch (Exception e) {
NucleusLogger.GENERAL.info(
">> Exception thrown persisting objects", e);
} finally {
if (tx.isActive()) {
tx.rollback();
}
}

// Perform some operation
tx = em.getTransaction();
try {

final List<B> list = em.createQuery("select b from B b order by b.id").getResultList();

tx.begin();

for(final B b : list) {
NucleusLogger.GENERAL.info(">> deleting {id: " + b.getId() + ", version: " + b.getVersion() + "}");
em.remove(b);
break;
}

tx.commit();
} catch (Exception e) {
NucleusLogger.GENERAL.info(">> Exception thrown retrieving objects", e);
} finally {
if (tx.isActive()) {
tx.rollback();
}
em.close();
}
}
}

yuri added a comment - 14/Jan/11 02:07 AM
It looks like JPA project does not have sources in the trunk:
https://datanucleus.svn.sourceforge.net/svnroot/datanucleus/platform/jpa/trunk/

I couldn't import the Team Project Set using this file
http://www.datanucleus.org/development/datanucleus-eclipse-projectSet.psf

from this page
http://www.datanucleus.org/development/building_eclipse.html

Any help would be greatly appreciated.
Thanks,
Yuri

Andy Jefferson added a comment - 14/Jan/11 07:27 AM
If wanting to debug on 2.x then you use code from under "branches/2.x"
All code under trunk (JPA is moved to "api.jpa") is for DN 3.0.

yuri added a comment - 14/Jan/11 08:18 AM
Oh, thanks. I'll modify datanucleus-eclipse-projectSet.psf to point to 2.x then.

Did you have a chance to re-run my second test? (It needs to be run at least twice to encounter the problem)

It would be very helpful if you could please confirm that the issue does not exist in the latest code and your database.

Thanks a lot!
Yuri