I have created the node and created 3 versions.
String path = "/my111";
MyClass m1 = new MyClass();
m1.setPath(path);
m1.setName("Myname");
m1.setLanguage("English");
ocm.create(m1);
ocm.save();
for (int i = 0; i < 4; i++) {
ocm.checkout(path);
m1.setName("mz676666" + i);
ocm.update(m1);
ocm.save();
ocm.checkin(path);
}
VersionIterator iterator = ocm.getAllVersions(path);
while (iterator.hasNext()) {
Version version = (Version)iterator.next();
System.out.println("version::"+version.getName());
}
Output :
version::jcr:rootVersion
version::1.0
version::1.1
version::1.2
version::1.3
Now i want to get the name
of a version 1.2
..
I tried it through
org.apache.jackrabbit.ocm.version.VersionIterator iterator = ocm.getAllVersions(path);
while (iterator.hasNext()) {
Version version = (Version)iterator.next();
System.out.println("version::"+version.getName());
MyClass m1 = (MyClass) ocm.getObject(path, version.getName());
System.out.println(m1.getName()); // But it always print `null`. Why??
}
Can it is possible to fire query and fetch the data?
How i can achieve this?
Please answer this.
Thanks in advance.
It is a long time since I do not work with Jackrabbit, so I might be wrong.
But as far as I remember, the content of a previous version node is stored as a frozen node under the version node.
So, I think you could try to retrieve it with:
VersionIterator iterator = ocm.getAllVersions(path);
while (iterator.hasNext()) {
Version version = (Version)iterator.next();
//Here you go:
MarketingZone m1 = (MarketingZone) version.getFrozenNode();
System.out.println(m1.getName());
}
Hope this helps.
Luca was right. Each Version has a frozen node which represents your node at the time it was checked in. You can call methods on it as you would the base node.
Version version = ...
Node node = version.getFrozenNode();
String name = node.getName();
// get a property, eg. someStringProperty
String someStringProperty = node.getProperty("someStringProperty").getString();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With