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.

Reply via email to