You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Roman Puchkovskiy <ro...@blandware.com> on 2008/05/06 20:46:58 UTC

Node.restore in transaction

Hi.

I'm experiencing problems with Node.restore inside transactions. In the
application, I have code like

Version bv = node.getBaseVersion();
node.restore(earlierVersion, true);
node.getVersionHistory().removeVersion(bv.getName()); // this fails

So I just try to remove base version first restoring node to one of previous
versions. But version removal fails saying that it's referenced; the only
reference is this node's "jcr:baseVersion" property which (if I undestand
this correctly) should be reset with second line (restore).

I tryed to write a simplified test case, and I came to one using
springmodules and Jencks for XA transactions. But in this test case it
behaves differently: NPE is thrown when Node.restore() is called from inside
a transaction and is not thrown when no transaction exists.

Main code is following:

        Node root = session.getRootNode();
        Node target = root.addNode(nodeName);
        target.addMixin("mix:versionable");
        root.save();
        
        VersionHistory vh = target.getVersionHistory();
        
        Version v1 = target.checkin();
        
        target.checkout();
        Version v2 = target.checkin();
        
        target.restore(v1.getName(), true);
        
        vh.removeVersion(v2.getName());

Here's the link to maven project with tests:
http://rpuch.narod.ru/test-versions-in-tx.zip
Tests may be run using 'mvn clean test'.

There're three tests: testRemoveVersionNoTx (no transaction, passes),
testRemoveVersionInTx (in transaction, fails),
testRemoveVersionInTxTwoTransactions (almost same, but works in two
transactions: first creates node and makes a version, then does the rest).
Two first tests use code shown above.

Repository configuration is default one (or very close to it), but same is
observed when I use Derby DB everywhere for FSs and PMs.

Can someone help: is my test code just incorrect, or maybe XA config is bad?
-- 
View this message in context: http://www.nabble.com/Node.restore-in-transaction-tp17089810p17089810.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.


Re: Node.restore in transaction

Posted by Roman Puchkovskiy <ro...@blandware.com>.
I've reproduced initial problem. Following method is test which fails:

    public void testRemoveVersionInTxThreeTransactions() {
        final String v1 = (String) transactionTemplate.execute(new
TransactionCallback() {
            public Object doInTransaction(TransactionStatus status) {
                return (String) jcrTemplate.execute(new JcrCallback() {
                    public Object doInJcr(Session session) throws
IOException,
                            RepositoryException {
                        Node target =
session.getRootNode().addNode("target3");
                        target.addMixin("mix:versionable");
                        session.save();
                        VersionHistory vh = target.getVersionHistory();
                        Version v1 = target.checkin();
                        return v1.getName();
                    }
                });
            }
        });
        final String v2 = (String) transactionTemplate.execute(new
TransactionCallback() {
            public Object doInTransaction(TransactionStatus status) {
                return jcrTemplate.execute(new JcrCallback() {
                    public Object doInJcr(Session session) throws
IOException,
                            RepositoryException {
                        Node target =
session.getRootNode().getNode("target3");
                        VersionHistory vh = target.getVersionHistory();
                        target.checkout();
                        Version v2 = target.checkin();
                        return v2.getName();
                    }
                });
            }
        });
        transactionTemplate.execute(new TransactionCallback() {
            public Object doInTransaction(TransactionStatus status) {
                jcrTemplate.execute(new JcrCallback() {
                    public Object doInJcr(Session session) throws
IOException,
                            RepositoryException {
                        Node target =
session.getRootNode().getNode("target3");
                        VersionHistory vh = target.getVersionHistory();
                        target.restore(v1, true);
                        vh.removeVersion(v2);
                        return null;
                    }
                });
                return null;
            }
        });
    }

Following exception is thrown:

testRemoveVersionInTxThreeTransactions(RemoveVersionInTxTest)  Time elapsed:
0.07 sec  <<< ERROR!
org.springframework.dao.DataIntegrityViolationException: Referential
integrity violated; nested exception is
javax.jcr.ReferentialIntegrityException: Unable to remove version. At least
once referenced.
	at
org.springmodules.jcr.SessionFactoryUtils.translateException(SessionFactoryUtils.java:221)
	at
org.springmodules.jcr.JcrAccessor.convertJcrAccessException(JcrAccessor.java:58)
	at org.springmodules.jcr.JcrTemplate.execute(JcrTemplate.java:82)
	at org.springmodules.jcr.JcrTemplate.execute(JcrTemplate.java:108)
	at RemoveVersionInTxTest$4.doInTransaction(RemoveVersionInTxTest.java:99)
	at
org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:128)
	at
RemoveVersionInTxTest.testRemoveVersionInTxThreeTransactions(RemoveVersionInTxTest.java:97)
Caused by: javax.jcr.ReferentialIntegrityException: Unable to remove
version. At least once referenced.
	at
org.apache.jackrabbit.core.version.InternalVersionHistoryImpl.removeVersion(InternalVersionHistoryImpl.java:365)
	at
org.apache.jackrabbit.core.version.AbstractVersionManager.removeVersion(AbstractVersionManager.java:475)
	at
org.apache.jackrabbit.core.version.XAVersionManager.removeVersion(XAVersionManager.java:394)
	at
org.apache.jackrabbit.core.version.XAVersionManager.removeVersion(XAVersionManager.java:174)
	at
org.apache.jackrabbit.core.version.VersionHistoryImpl.removeVersion(VersionHistoryImpl.java:222)
	at RemoveVersionInTxTest$4$1.doInJcr(RemoveVersionInTxTest.java:105)
	at org.springmodules.jcr.JcrTemplate.execute(JcrTemplate.java:76)
	... 30 more

In this test, node is created and checked-in in first transaction, then
checked-out and checked-in in second transaction (so second version is
created), then node is restored to version 1 and its last version (version
2) is tried to be removed in third transaction - which fails.
If we put creation of second version, node restore and removal of first
version in one transaction, test does not fail.
-- 
View this message in context: http://www.nabble.com/Node.restore-in-transaction-tp17089810p17100346.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.


Re: Node.restore in transaction

Posted by Roman Puchkovskiy <ro...@blandware.com>.
Sorry for hasty posts. I've just rerun tests with Jackrabbit 1.4.3 and
Jackrabbit 1.4.4 and in both cases all tests worked fine. Thanks :) I
wrongly assumed that Jackrabbit 1.4.3 is not yet available through Maven
repositories.


Marcel Reutegger wrote:
> 
> Hi,
> 
> what version of jackrabbit are you using?
> 
> this might be related to https://issues.apache.org/jira/browse/JCR-1476
> which is fixed in 1.4.3.
> 
> regards
>   marcel
> 
> Roman Puchkovskiy wrote:
>> Here's exception which is thrown by failing test:
>> 
>> java.lang.NullPointerException
>> 	at
>> org.apache.jackrabbit.core.NodeImpl.restoreFrozenState(NodeImpl.java:3872)
>> 	at
>> org.apache.jackrabbit.core.NodeImpl.internalRestore(NodeImpl.java:3840)
>> 	at
>> org.apache.jackrabbit.core.NodeImpl.internalRestore(NodeImpl.java:3801)
>> 	at org.apache.jackrabbit.core.NodeImpl.restore(NodeImpl.java:3072)
>> 	at
>> RemoveVersionInTxTest.doTestRemoveVersion(RemoveVersionInTxTest.java:62)
>> 	at RemoveVersionInTxTest.access$100(RemoveVersionInTxTest.java:22)
>> 	at RemoveVersionInTxTest$1$1.doInJcr(RemoveVersionInTxTest.java:33)
>> 	at org.springmodules.jcr.JcrTemplate.execute(JcrTemplate.java:76)
>> 	at org.springmodules.jcr.JcrTemplate.execute(JcrTemplate.java:108)
>> 	at
>> RemoveVersionInTxTest$1.doInTransaction(RemoveVersionInTxTest.java:30)
>> 	at
>> org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:128)
>> 	at
>> RemoveVersionInTxTest.testRemoveVersionInTx(RemoveVersionInTxTest.java:28)
>> 	at
>> RemoveVersionInTxTest.testRemoveVersionInTx(RemoveVersionInTxTest.java:28)
>> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> 	at
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>> 	at
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>> 	at java.lang.reflect.Method.invoke(Method.java:597)
>> 	at junit.framework.TestCase.runTest(TestCase.java:154)
>> 	at junit.framework.TestCase.runBare(TestCase.java:127)
>> 	at junit.framework.TestResult$1.protect(TestResult.java:106)
>> 	at junit.framework.TestResult.runProtected(TestResult.java:124)
>> 	at junit.framework.TestResult.run(TestResult.java:109)
>> 	at junit.framework.TestCase.run(TestCase.java:118)
>> 	at junit.framework.TestSuite.runTest(TestSuite.java:208)
>> 	at junit.framework.TestSuite.run(TestSuite.java:203)
>> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> 	at
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>> 	at
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>> 	at java.lang.reflect.Method.invoke(Method.java:597)
>> 	at
>> org.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:213)
>> 	at
>> org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:138)
>> 	at
>> org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:125)
>> 	at org.apache.maven.surefire.Surefire.run(Surefire.java:132)
>> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> 	at
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>> 	at
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>> 	at java.lang.reflect.Method.invoke(Method.java:597)
>> 	at
>> org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:308)
>> 	at
>> org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:879)
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Node.restore-in-transaction-tp17089810p17121683.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.


Re: Node.restore in transaction

Posted by Roman Puchkovskiy <ro...@blandware.com>.
Hi. Thanks for reply.
We're using Jackrabbit 1.4.2. Indeed, it seems that JCR-1476 is the problem
which caused our NPE.
But please note, that there's another failing test
(testRemoveVersionInTxThreeTransactions()) which does not throw NPE (and
restores node successfully) but fails to remove version which was
base-version before restore. Do you think that JCR-1476 causes this problem
too, or is this another problem?


Marcel Reutegger wrote:
> 
> Hi,
> 
> what version of jackrabbit are you using?
> 
> this might be related to https://issues.apache.org/jira/browse/JCR-1476
> which is fixed in 1.4.3.
> 
> regards
>   marcel
> 
> Roman Puchkovskiy wrote:
>> Here's exception which is thrown by failing test:
>> 
>> java.lang.NullPointerException
>> 	at
>> org.apache.jackrabbit.core.NodeImpl.restoreFrozenState(NodeImpl.java:3872)
>> 	at
>> org.apache.jackrabbit.core.NodeImpl.internalRestore(NodeImpl.java:3840)
>> 	at
>> org.apache.jackrabbit.core.NodeImpl.internalRestore(NodeImpl.java:3801)
>> 	at org.apache.jackrabbit.core.NodeImpl.restore(NodeImpl.java:3072)
>> 	at
>> RemoveVersionInTxTest.doTestRemoveVersion(RemoveVersionInTxTest.java:62)
>> 	at RemoveVersionInTxTest.access$100(RemoveVersionInTxTest.java:22)
>> 	at RemoveVersionInTxTest$1$1.doInJcr(RemoveVersionInTxTest.java:33)
>> 	at org.springmodules.jcr.JcrTemplate.execute(JcrTemplate.java:76)
>> 	at org.springmodules.jcr.JcrTemplate.execute(JcrTemplate.java:108)
>> 	at
>> RemoveVersionInTxTest$1.doInTransaction(RemoveVersionInTxTest.java:30)
>> 	at
>> org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:128)
>> 	at
>> RemoveVersionInTxTest.testRemoveVersionInTx(RemoveVersionInTxTest.java:28)
>> 	at
>> RemoveVersionInTxTest.testRemoveVersionInTx(RemoveVersionInTxTest.java:28)
>> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> 	at
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>> 	at
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>> 	at java.lang.reflect.Method.invoke(Method.java:597)
>> 	at junit.framework.TestCase.runTest(TestCase.java:154)
>> 	at junit.framework.TestCase.runBare(TestCase.java:127)
>> 	at junit.framework.TestResult$1.protect(TestResult.java:106)
>> 	at junit.framework.TestResult.runProtected(TestResult.java:124)
>> 	at junit.framework.TestResult.run(TestResult.java:109)
>> 	at junit.framework.TestCase.run(TestCase.java:118)
>> 	at junit.framework.TestSuite.runTest(TestSuite.java:208)
>> 	at junit.framework.TestSuite.run(TestSuite.java:203)
>> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> 	at
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>> 	at
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>> 	at java.lang.reflect.Method.invoke(Method.java:597)
>> 	at
>> org.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:213)
>> 	at
>> org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:138)
>> 	at
>> org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:125)
>> 	at org.apache.maven.surefire.Surefire.run(Surefire.java:132)
>> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> 	at
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>> 	at
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>> 	at java.lang.reflect.Method.invoke(Method.java:597)
>> 	at
>> org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:308)
>> 	at
>> org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:879)
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Node.restore-in-transaction-tp17089810p17120165.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.


Re: Node.restore in transaction

Posted by Marcel Reutegger <ma...@gmx.net>.
Hi,

what version of jackrabbit are you using?

this might be related to https://issues.apache.org/jira/browse/JCR-1476
which is fixed in 1.4.3.

regards
  marcel

Roman Puchkovskiy wrote:
> Here's exception which is thrown by failing test:
> 
> java.lang.NullPointerException
> 	at
> org.apache.jackrabbit.core.NodeImpl.restoreFrozenState(NodeImpl.java:3872)
> 	at org.apache.jackrabbit.core.NodeImpl.internalRestore(NodeImpl.java:3840)
> 	at org.apache.jackrabbit.core.NodeImpl.internalRestore(NodeImpl.java:3801)
> 	at org.apache.jackrabbit.core.NodeImpl.restore(NodeImpl.java:3072)
> 	at RemoveVersionInTxTest.doTestRemoveVersion(RemoveVersionInTxTest.java:62)
> 	at RemoveVersionInTxTest.access$100(RemoveVersionInTxTest.java:22)
> 	at RemoveVersionInTxTest$1$1.doInJcr(RemoveVersionInTxTest.java:33)
> 	at org.springmodules.jcr.JcrTemplate.execute(JcrTemplate.java:76)
> 	at org.springmodules.jcr.JcrTemplate.execute(JcrTemplate.java:108)
> 	at RemoveVersionInTxTest$1.doInTransaction(RemoveVersionInTxTest.java:30)
> 	at
> org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:128)
> 	at
> RemoveVersionInTxTest.testRemoveVersionInTx(RemoveVersionInTxTest.java:28)
> 	at
> RemoveVersionInTxTest.testRemoveVersionInTx(RemoveVersionInTxTest.java:28)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> 	at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> 	at java.lang.reflect.Method.invoke(Method.java:597)
> 	at junit.framework.TestCase.runTest(TestCase.java:154)
> 	at junit.framework.TestCase.runBare(TestCase.java:127)
> 	at junit.framework.TestResult$1.protect(TestResult.java:106)
> 	at junit.framework.TestResult.runProtected(TestResult.java:124)
> 	at junit.framework.TestResult.run(TestResult.java:109)
> 	at junit.framework.TestCase.run(TestCase.java:118)
> 	at junit.framework.TestSuite.runTest(TestSuite.java:208)
> 	at junit.framework.TestSuite.run(TestSuite.java:203)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> 	at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> 	at java.lang.reflect.Method.invoke(Method.java:597)
> 	at
> org.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:213)
> 	at
> org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:138)
> 	at
> org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:125)
> 	at org.apache.maven.surefire.Surefire.run(Surefire.java:132)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> 	at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> 	at java.lang.reflect.Method.invoke(Method.java:597)
> 	at
> org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:308)
> 	at
> org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:879)


Re: Node.restore in transaction

Posted by Roman Puchkovskiy <ro...@blandware.com>.
Here's exception which is thrown by failing test:

java.lang.NullPointerException
	at
org.apache.jackrabbit.core.NodeImpl.restoreFrozenState(NodeImpl.java:3872)
	at org.apache.jackrabbit.core.NodeImpl.internalRestore(NodeImpl.java:3840)
	at org.apache.jackrabbit.core.NodeImpl.internalRestore(NodeImpl.java:3801)
	at org.apache.jackrabbit.core.NodeImpl.restore(NodeImpl.java:3072)
	at RemoveVersionInTxTest.doTestRemoveVersion(RemoveVersionInTxTest.java:62)
	at RemoveVersionInTxTest.access$100(RemoveVersionInTxTest.java:22)
	at RemoveVersionInTxTest$1$1.doInJcr(RemoveVersionInTxTest.java:33)
	at org.springmodules.jcr.JcrTemplate.execute(JcrTemplate.java:76)
	at org.springmodules.jcr.JcrTemplate.execute(JcrTemplate.java:108)
	at RemoveVersionInTxTest$1.doInTransaction(RemoveVersionInTxTest.java:30)
	at
org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:128)
	at
RemoveVersionInTxTest.testRemoveVersionInTx(RemoveVersionInTxTest.java:28)
	at
RemoveVersionInTxTest.testRemoveVersionInTx(RemoveVersionInTxTest.java:28)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at junit.framework.TestCase.runTest(TestCase.java:154)
	at junit.framework.TestCase.runBare(TestCase.java:127)
	at junit.framework.TestResult$1.protect(TestResult.java:106)
	at junit.framework.TestResult.runProtected(TestResult.java:124)
	at junit.framework.TestResult.run(TestResult.java:109)
	at junit.framework.TestCase.run(TestCase.java:118)
	at junit.framework.TestSuite.runTest(TestSuite.java:208)
	at junit.framework.TestSuite.run(TestSuite.java:203)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at
org.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:213)
	at
org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:138)
	at
org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:125)
	at org.apache.maven.surefire.Surefire.run(Surefire.java:132)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at
org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:308)
	at
org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:879)
-- 
View this message in context: http://www.nabble.com/Node.restore-in-transaction-tp17089810p17098276.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.