Custom Entity Factory Problems

Posts   
 
    
Dan Suitor
User
Posts: 16
Joined: 07-Feb-2008
# Posted on: 07-Feb-2008 15:48:40   

I’m having a problem when defining an overridden Entity Factory. I think that the core of the problem is the object that the factory is responsible for creating inherits from a class that is also inherited from by another LLBLgen generated class.

                          EntityClass(LLBL Generated)

| DbEntityClass(LLBL Generated) | --------------------------------------- | | MyDbEntityClass DbEntityClass2(LLBL Generated)

The factory I created inherits from the DbEntityClass’s factory and creates the type of object MyDbEntityClass. When I try to fetch from the database, an exception gets thrown with the message "entityToAdd isn't of the right type". If I break the DbEntityClass to DbEntityClass2 relationship, it works.

Am I trying to do something I’m not supposed to or is there another way to achieve this?

Thanks Dan

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 08-Feb-2008 10:23:33   

That's because the fetch is polymorphic. This means that not every instance in fetched collection is of the same type (of the Super type), but some are of the derived DbEntityClass2 type.

And this fails if you are using a factory of that creates objects which don't extend the filled in entities. Since you are using a factory to create MyDbEntityClass which is not a subType of DbEntityClass2 .

If I break the DbEntityClass to DbEntityClass2 relationship, it works.

Would you please explain the above line.