Hi,
I found a unexpected exception during restoring node, which has child
referenced. I tested following scenario :
1. Create root node,
2. Add 1st child node (CHILD_0) below root node,
3. Add 2nd child node (CHILD_1) below root node,
4. Create reference property on 2nd node (CHILD_1) to 1st node (CHILD_0),
5. Create new version of root node (checkout -> set some property ->
checkin),
6. Try to restore root node to previous version.
When I try to restore root node exception occurs:
javax.jcr.ItemNotFoundException:
f201e30f-42f2-46b6-bdab-8aa472777c92/{http://www.jcp.org/jcr/1.0}primaryType
10:53:22,031 INFO
com.oyster.mom.contentserver.prototyping.it5.TestRestoreNodeWithChildReferenced.main(TestRestoreNodeWithChildReferenced.java:63)
- Initial version : 1.0
10:53:22,140 INFO
com.oyster.mom.contentserver.prototyping.it5.TestRestoreNodeWithChildReferenced.main(TestRestoreNodeWithChildReferenced.java:70)
- Next version : 1.1
javax.jcr.ItemNotFoundException:
59842503-3277-421f-896c-86c508ad8e76/{http://www.jcp.org/jcr/1.0}isCheckedOut
at
org.apache.jackrabbit.core.ItemManager.createItemInstance(ItemManager.java:467)
at org.apache.jackrabbit.core.ItemManager.getItem(ItemManager.java:319)
at
org.apache.jackrabbit.core.ItemImpl.restoreTransientItems(ItemImpl.java:691)
at org.apache.jackrabbit.core.ItemImpl.save(ItemImpl.java:1192)
at org.apache.jackrabbit.core.SessionImpl.save(SessionImpl.java:758)
at
org.apache.jackrabbit.core.NodeImpl.internalRestore(NodeImpl.java:3502)
at org.apache.jackrabbit.core.NodeImpl.restore(NodeImpl.java:2848)
at
com.oyster.mom.contentserver.prototyping.it5.TestRestoreNodeWithChildReferenced.main(TestRestoreNodeWithChildReferenced.java:74)
10:53:22,281 INFO
com.oyster.mom.contentserver.prototyping.it5.TestRestoreNodeWithChildReferenced.main(TestRestoreNodeWithChildReferenced.java:84)
- Done.
Find attached source test.
Regards
Przemo Pakulski
www.cognifide.com
/*
* Created by Cognifide on 2006-12-11
*/
package com.oyster.mom.contentserver.prototyping.it5;
import javax.jcr.Node;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import javax.jcr.version.Version;
import org.apache.jackrabbit.core.RepositoryImpl;
import org.apache.jackrabbit.core.config.RepositoryConfig;
/**
* @author przemyslaw_pakulski
*/
public class TestRestoreNodeWithChildReferenced {
private static final org.apache.commons.logging.Log log =
org.apache.commons.logging.LogFactory
.getLog(TestRestoreNodeWithChildReferenced.class);
public static String REPOSITORY_HOME = "D:/repo/jndi/";
public static String REPOSITORY_CONFIG = REPOSITORY_HOME + "repository.xml";
public static String CHILD_NAME = "child";
public static void main(String[] args) throws RepositoryException {
System.setProperty("java.security.auth.login.config",
"jaas_jcr.config");
RepositoryConfig config = RepositoryConfig.create(REPOSITORY_CONFIG,
REPOSITORY_HOME);
Repository repository = RepositoryImpl.create(config);
Session session = repository.login(new SimpleCredentials("admin",
"admin".toCharArray()));
/*
* build some simple hierarchy as presented below:
*
* child1 references child0
*
* node +--child0 <--|
* +--child1 ---|
*/
Node root = session.getRootNode();
Node node = root.addNode("node");
node.addMixin("mix:versionable");
Node child0 = node.addNode(CHILD_NAME);
child0.addMixin("mix:versionable");
Node child1 = node.addNode(CHILD_NAME);
child1.addMixin("mix:versionable");
child1.setProperty("reference", child0);
root.save();
child0.checkin();
child1.checkin();
node.checkin();
Version version = node.getBaseVersion();
log.info("Initial version : " + version.getName());
// prepare next version
node.checkout();
node.setProperty("test", true);
node.save();
node.checkin();
log.info("Next version : " + node.getBaseVersion().getName());
try {
// try to restore node to initial version
node.restore(version, false);
}
catch (RepositoryException e) {
e.printStackTrace();
}
session.logout();
((RepositoryImpl) repository).shutdown();
log.info("Done.");
}
}