You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Ераскин Алексей <er...@1c.ru> on 2008/11/10 12:35:31 UTC

Working with JackRabbit OCM

Hi guys!

I'm new to JackRabbit and now I'm in process of testing JackRabbit OCM
feature.

I'm stuck with the following issue:

 

I have class Parent: 

 

@Node

class Parent {

            @Field

private String text;

 

            public String getText(){

                        return this.text;

}

 

public void setText(String text){

            this.text = text;

}                       

}

 

and child class:

 

@Node(extend=Parent.class)

class Child {

            

            private String y;

            

            @Override

public String getText(){

            return this.y;

}

 

@Override

public void setText(String text){

            this.y = text;

}

} 

 

and doing following:

 

: 

Child child = new Child();

child.setText("this is child"); // as I understand that code save to "y"
attribute

 

ocm.insert(child);

ocm.save();

 

QueryManager manager = ocm.getQueryManager();

Filter filter = manager.createFilter(AdvTextQuestionData.class);

filter.addLike("text", "%this is child%");

 

Query query = manager.createQuery(filter);

 

Collection t1 = ocm.getObjects(query);

 

:.

 

In result, collection isn't empty because OCM saves to repository to the
"text" property(annotated field in Parent class) following value: "this is
child" Why?

Actually I don't set this field and for me it's strange behavior: maybe
someone knows something about that?

 

Tnx a lot, Eraskin Alexey!

 


Re: Working with JackRabbit OCM

Posted by Christophe Lombart <ch...@gmail.com>.
On Mon, Nov 10, 2008 at 12:35, Ераскин Алексей <er...@1c.ru> wrote:

In result, collection isn't empty because OCM saves to repository to the
> "text" property(annotated field in Parent class) following value: "this is
> child" Why?
>

Because the Child class "extends" the Parent Class (see
@Node(extend=Parent.class) ) in term of OCM mapping and not in term of java.


 "@Node(extend=Parent.class)"  is a way to get all mapping info from an
ancestor class. this is only used  for an inheritance tree which is not your
case I think.

You can solve the problem by replacing "@Node(extend=Parent.class)" by @Node
and add mapping info in the Child class.

FYI, "extend" attribute in @Node is obsolete. I will add a tutorial on the
inheritance support. From now, with the latest build from subversion, it is
possible to write :

@Node
Class MyAncestor
{
     // Add  fields here
}

@Node
Class MyClass extends MyAncestor
{
   // Add  fields here
}

MyClass will inherit all mapping info made in the MyAncestor because it is a
descendant of MyAncestor.


 Let me know if you need more info

br,
Christophe