jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gaetano Sferra <gsfe...@imnet.it>
Subject Re: Jackrabbit and OCM annotations troubles
Date Tue, 30 Dec 2008 14:03:30 GMT
Hi Todd,

Todd Seiber ha scritto:
> 2. I believe that you need to register the ocm namespace but I cannot
> remember if that is the only thing you need to do. Try
> ws.getNamespaceRegistry().registerNamespace("ocm", "
> http://jackrabbit.apache.org/ocm");
>   
I've already registered it. If you take a look at the main method in the 
source code posted you will find the namespace registration code :)
It doesn't help... ;(
> 3. OCM is creating your node as nt:unstructured since you have not specified
> your own jcrType. When it tries to read it from the repository it will not
> find a dicriminator to tell it what type of object it is so it will try to
> look it up in your annotations by the jcrType.
>    You can try creating and registering your own node type such as ns:Type
> which inherits nt:unstructured. (cnd: [ns:Type] > nt:unstructured). Then
> specify jcrType="ns:Type". This would allow OCM to work as expected.
>   
But I've specified jcrSuperTypes="nt:base" in @Node annotation, 
shouldn't it means like "inherits from nt:base"?
Maybe it isn't enough and I've to register my nodetypes using CND? ;(
> I had started using annotations but have moved to using the xml mapping file
> instead because of many of these issues. I just found it easier to develop.
>   
That's a good idea. I definitely forgot about this option. Thank you! :)
> On Tue, Dec 30, 2008 at 4:57 AM, Gaetano Sferra <gsferra@imnet.it> wrote:
>
>   
>> Hi,
>>
>> I'm facing a lot of difficulties using Jackrabbit 1.4 and hope someone will
>> help me.
>> 1 - Instantiating a TransientRepository using JDK 1.5 throws a
>> "java.lang.UnsupportedClassVersionError: Bad version number in .class file"
>> (Jackrabbit should support JDK 1.4 at least, isn't it?)
>>
>> 2 - Define a simple node class using @Node annotation without specify
>> "discriminator=false" will result in a "Unknown mixin type ocm:discriminator
>> for mapped class class Type; nested exception is
>> javax.jcr.nodetype.NoSuchNodeTypeException: {
>> http://jackrabbit.apache.org/ocm}discriminator<http://jackrabbit.apache.org/ocm%7Ddiscriminator>";
>> eg:
>>
>> @Node
>> public class Type {
>>   @Field(path=true) private path;
>>   @Field(uuid=true) private uuid;
>>   @Field private String description;
>>   // Getter and setter follows..
>> }
>>
>> 3 - What's wrong in following code? (throws "Node type: nt:unstructured has
>> no descriptor" on getObject(String)):
>>
>> @Node(discriminator=false, jcrSuperTypes="nt:base",
>> jcrMixinTypes="mix:referenceable")
>> public class Type {
>>  @Field(path=true) private String path;
>>  @Field(uuid=true) private String uuid;
>>  @Field private String description;
>>  // Getter and setter follows..
>> }
>>
>> @Node(discriminator=false, jcrMixinTypes="mix:versionable")
>> public class Element {
>>  @Field(path=true) private String path;
>>  @Bean(converter=ReferenceBeanConverterImpl.class) private Type type;
>>  // Getter and setter follows..
>> }
>>
>> public class Main {
>>   public static void main(String[] args) {
>>       Logger logger = Logger.getLogger(Main.class.getName());
>>       ArrayList<Class> classes = null;
>>       ObjectContentManager ocm = null;
>>       Mapper mapper = null;
>>       Session session = null;
>>       Repository repository = null;
>>
>>       try {
>>           repository = new TransientRepository();
>>           session = repository.login(new SimpleCredentials("user",
>> "pass".toCharArray()));
>>           try {
>>
>> session.getWorkspace().getNamespaceRegistry().registerNamespace("ocm", "
>> http://jackrabbit.apache.org/ocm");
>>           } catch (NamespaceException nsce) {
>>               logger.info(nsce.getMessage());
>>           }
>>
>>           classes = new ArrayList<Class>();
>>           classes.add(Type.class);
>>           classes.add(Element.class);
>>               mapper = new AnnotationMapperImpl(classes);
>>           ocm = new ObjectContentManagerImpl(session, mapper);
>>
>>           Type type = new Type();
>>           type.setPath("/primary");
>>           type.setDescription("My primary element type");
>>           ocm.insert(type);
>>           ocm.save();
>>               Element element = new Element();
>>           element.setPath("/first-element");
>>           element.setType((Type) ocm.getObject("/primary"));
>>           ocm.insert(element);
>>           ocm.save();
>>       } catch (Exception e) {
>>           logger.severe(e.getMessage());
>>       }
>>   }
>> }
>>
>> I'm searching on this ML and looking at test code but everything seems so
>> easy and clean that I really not able to find something wrong.
>> Please help, thank you.
>> --
>> GaS
>>
>>     
>
>   


-- 

Gaetano Sferra
**Interactive Media S.p.A.**
Via Luca Guarico, 9 - 00143 Roma (RM)
tel. +39 06 54642415
fax. +39 06 54642515
e-mail gsferra@imnet.it <mailto:gsferra@imnet.it>
www.interactivemedia.it <http://www.interactivemedia.it/>


Mime
View raw message