Hi Ruchi, If you want to use the same JCR node type for the complete class hierarchy, you have to specify discriminator = true. By this way, the persistence manager will add a new property which will contain the object class. This is technique is often used in ORM. This property is used to instantiate correctly the object.
If you set the discriminator = false, it means that your have one different JCR node type per class for the complete hierarchy. That means the discriminator is not necessary. Thanks to the jcr node type it is possible to retrieve the right java class. Are you using JCR custom node types ? You can send me your OCM mapping file. There are some examples in the unit tests. On 9/14/06, Ruchi Goel <[EMAIL PROTECTED]> wrote:
Hi, I am trying a simple save and then query for a java object via jcrmapping. I ahve two questions : 1. What is the concept of "discriminator " and when is it set to true/false ? 2. I have set discriminator = falsein mapping file.In a successive save and read , I am able to save a node via the following : Ad ad = new Ad(); ad.setPath("/ad"); ad.setTitle("IT"); ad.setText("This ad is for IT jobs"); ad.setImageAsLink("http://http://incubator.apache.org/images/apache-incubator-logo.png"); Collection links = new ArrayList(); links.add((String)"http://yahoo.com"); links.add((String)"http://google.com"); ad.setLinks(links); try{ FileInputStream fis = new FileInputStream("c:/tmp/Sun_logo.gif"); ad.setImageAsBinary(fis); }catch(IOException ioe){ System.out.println(ioe.getMessage()); System.exit(0); } pm.insert(ad); pm.save(); , but when I try to read it back via following : public Ad getAd(String title){ Filter filter = qm.createFilter(Ad.class); filter.addEqualTo("title", title); Query query = qm.createQuery(filter); Ad ad = (Ad)pm.getObject(query); return ad; }; The result says : Exception in thread "main" org.apache.portals.graffito.jcr.exception.PersistenceException: Impossible to get the object - the query returns more than one object at org.apache.portals.graffito.jcr.persistence.impl.PersistenceManagerImpl.getObject(PersistenceManagerImpl.java:454) at com.sun.portal.cms.service.AdModelServiceImpl.getAd(AdModelServiceImpl.java:54) at com.sun.portal.cms.Test.testReadAd(Test.java:57) at com.sun.portal.cms.Test.main(Test.java:69) while I check in the repository, I have exactly one node with this title. If I try to read the collection of objects , I get the following error : Exception in thread "main" org.apache.portals.graffito.jcr.exception.JcrMappingException: Impossible to find the classdescriptor for /ad. There is no discriminator and associated JCR node type at org.apache.portals.graffito.jcr.persistence.objectconverter.impl.ObjectConverterImpl.getObject(ObjectConverterImpl.java:271) at org.apache.portals.graffito.jcr.persistence.impl.PersistenceManagerImpl.getObjects(PersistenceManagerImpl.java:492) at com.sun.portal.cms.service.AdModelServiceImpl.getAd(AdModelServiceImpl.java:55) at com.sun.portal.cms.Test.testReadAd(Test.java:57) at com.sun.portal.cms.Test.main(Test.java:69) Java Result: 1 I am sure I am missing something here , but cannot trace it . I am able to do teh above operations via directly using JSR170 calls. Any help appreciated. Thanks, Ruchi
-- Best regards, Christophe