How to register a class for object binding?

18 views
Skip to first unread message

lari...@mail.com

unread,
Mar 2, 2015, 11:11:51 AM3/2/15
to
I read the documentation and some blog articles and I get contradictory information. I am trying to fix the following error:

"Type Card cannot be serialized because is not part of registered entities. To fix this error register this class"

I found that class could be registred  like this

db.getEntityManager().registerEntityClasses( Card.class );

But that gives me a compilation error

"The method registerEntityClass (Collection <String>) in the type OEntityManager is not applicable for the arguments ( Class<Card> )"

Now from what I understand, it only want a string as parameter. But passing "Card.class" as a string does not work either. According to the documention it is specified that:

Before to use persistent POJOs OrientDB needs to know which classes are persistent (between thousands in your classpath) by registering the persistent packages and/or classes. Example:

database.getEntityManager().registerEntityClasses("com.orientechnologies.orient.test.domain");

This must be done only right after the database is created or opened.



Notice the "and/or", so I should be able to pass only a class. But now if I want to register the whole package, I imagine I use the package name and add ".domain" to the package. The problem is that my test code has no package name, so how I am supposed to register the whole package? Again, what if not all classes in a package are serializable, could I not just specify classes individually? I am forces to place serializable class in a separate package?

Here is a copy of the card class

public class Card
{
    private String name;
    private int cost;
    private int strength;   
   
    public Card () {}
   
    public String getName ( ) {    return name; }
    public void setName ( String value ) { name = value; }
   
    public int getCost () { return cost; }
    public void setCost ( int value ) { cost = value; }
   
    public int getStrength () { return strength; }
    public void setStrength ( int value ) { strength = value; }
   
}


Reply all
Reply to author
Forward
0 new messages