You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Ramiro Aparicio <ra...@prot-on.com> on 2013/01/03 18:54:28 UTC

Deleting object rendes an instanciation exception

Hi and happy new year to everyone,

I am back with my happy inheritance one more time.
I am using single table inheritance and just in case someone did not 
remember the model here is a simplification about it:

abstract SessionLog it has relations to other tables as Log or User
SessionLogApi and SessionLogWeb that inherits from SessionLog they have 
specific information about the session type and their own relations

I have found some problems with this kind of mapping but till now I have 
always find a way to hack around Cayenne problems with this and today 
(we are really near to put the new version with inheritance in 
production) I have struck against this exception:

Caused by: org.apache.cayenne.CayenneRuntimeException: [v.3.1B1 May 28 
2012 18:42:43] Error creating object of class 
'com.proton.ks.persistence.SessionLog'
at 
org.apache.cayenne.reflect.PersistentDescriptor.createObject(PersistentDescriptor.java:288)
at 
org.apache.cayenne.reflect.LazyClassDescriptorDecorator.createObject(LazyClassDescriptorDecorator.java:73)
at 
org.apache.cayenne.access.DataContext.findOrCreateObject(DataContext.java:1178)
at 
org.apache.cayenne.access.ObjectResolver.objectFromDataRow(ObjectResolver.java:151)
at 
org.apache.cayenne.access.ObjectResolver.objectFromDataRow(ObjectResolver.java:137)
at 
org.apache.cayenne.access.ObjectResolver.objectsFromDataRows(ObjectResolver.java:121)
at 
org.apache.cayenne.access.ObjectResolver.synchronizedObjectsFromDataRows(ObjectResolver.java:102)
at 
org.apache.cayenne.access.ObjectResolver.synchronizedRootResultNodeFromDataRows(ObjectResolver.java:93)
at 
org.apache.cayenne.access.DataDomainQueryAction$ObjectConversionStrategy.toResultsTree(DataDomainQueryAction.java:581)
at 
org.apache.cayenne.access.DataDomainQueryAction$SingleObjectConversionStrategy.convert(DataDomainQueryAction.java:637)
at 
org.apache.cayenne.access.DataDomainQueryAction.interceptObjectConversion(DataDomainQueryAction.java:465)
at 
org.apache.cayenne.access.DataDomainQueryAction.execute(DataDomainQueryAction.java:129)
at 
org.apache.cayenne.access.DataDomain.onQueryNoFilters(DataDomain.java:754)
at 
org.apache.cayenne.access.DataDomain$DataDomainQueryFilterChain.onQuery(DataDomain.java:1003)
at org.apache.cayenne.access.DataDomain.onQuery(DataDomain.java:744)
at 
org.apache.cayenne.util.ObjectContextQueryAction.runQuery(ObjectContextQueryAction.java:350)
at 
org.apache.cayenne.util.ObjectContextQueryAction.executePostCache(ObjectContextQueryAction.java:106)
at 
org.apache.cayenne.util.ObjectContextQueryAction.execute(ObjectContextQueryAction.java:93)
at org.apache.cayenne.access.DataContext.onQuery(DataContext.java:989)
at org.apache.cayenne.access.DataContext.performQuery(DataContext.java:978)
at 
org.apache.cayenne.util.RelationshipFault.resolveFromDB(RelationshipFault.java:89)
at 
org.apache.cayenne.util.PersistentObjectList.resolvedObjectList(PersistentObjectList.java:301)
at 
org.apache.cayenne.util.PersistentObjectList.toArray(PersistentObjectList.java:278)
at java.util.ArrayList.(ArrayList.java:131)
at 
org.apache.cayenne.ObjectContextDeleteAction.toCollection(ObjectContextDeleteAction.java:124)
at 
org.apache.cayenne.ObjectContextDeleteAction.processDeleteRules(ObjectContextDeleteAction.java:153)
at 
org.apache.cayenne.ObjectContextDeleteAction.deletePersistent(ObjectContextDeleteAction.java:112)
at 
org.apache.cayenne.ObjectContextDeleteAction.performDelete(ObjectContextDeleteAction.java:91)
at org.apache.cayenne.BaseContext.deleteObjects(BaseContext.java:698)
at 
com.proton.cayenne.utils.CayenneTemplate.deleteObject(CayenneTemplate.java:79)
at 
com.proton.ks.services.business.HostingService.rejectUserRequestToDomain(SourceFile:413)
... 120 more
Caused by: java.lang.InstantiationException
at 
sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:30)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at 
org.apache.cayenne.reflect.PersistentDescriptor.createObject(PersistentDescriptor.java:285)
... 150 more

In case it is not clear in the trace I am only doing a 
context.deleteObjects(user) that user is cascading throught the model 
and in some way hitting a SessionLogApi or SessionLogWeb which Cayenne 
treats as a standard SessionLog and fails.

I hope Andrus can help with this, at least with a way to circunvent the 
error as the fix, if feasible, will take some time to arrive a Cayenne 
release version.

As always just ask for model, tests, or whatever as I am happy to 
provide them.

Thank you in advance and merry christmas

Re: Date or Timestamp

Posted by Michael Gentry <mg...@masslight.net>.
Hi there,

You can choose java.sql.Timestamp in the ObjEntity and TIMESTAMP in the
DbEntity.

mrg



On Mon, Jan 14, 2013 at 2:47 PM, emeka okafor <em...@yahoo.com> wrote:

> I am working with h2 at the moment and the modeler is mapping
> java.util.Date to the database Date type but I would live to have the
> datebase "Timestamp" type. How do I handle this with cayenne?
>

Date or Timestamp

Posted by emeka okafor <em...@yahoo.com>.
I am working with h2 at the moment and the modeler is mapping java.util.Date to the database Date type but I would live to have the datebase "Timestamp" type. How do I handle this with cayenne?

Re: many2many + single table inheritance

Posted by emeka okafor <em...@yahoo.com>.
Yes, I tried what you said and it seems to work in most cases. As my model grows and becomes more complicated, I have to do a lot of fiddling at some places in my code. I think I am going to get rid of inheritance and only work with data.
Thanks lot.


________________________________
 From: Ramiro Aparicio <ra...@prot-on.com>
To: user@cayenne.apache.org 
Sent: Monday, January 14, 2013 10:30 AM
Subject: Re: many2many + single table inheritance
 
I have been working with inheritance a lot lately but finally I had to 
remove it from my model.

If Base is an abstract class you will have problems at deleting A o Base 
child objects.
Anyway in your case you want to make 3 relationships, A<-Base A->Base1 
A->Base2 (the arrows are not for cardinality just to tell where do you 
want to model the relationships) this will render some warnings or 
notices in the modeller, but will work ok with your current usage.

El 13/01/2013 13:46, emeka okafor escribió:
>
> Hello again,
> I have been trying to simplify some parts of my code and so I figured the following will work:
>
> I have a many-to-many relation, say A <<->> Base
> Base has two subclasses, say Base1 andBase2 modeled using single table inheritance,
> so basically:
> <obj-entity name="Base1" superEntityName="Base" className="Base1">
>
> <qualifier><![CDATA[Type = "BASE1"]]></qualifier>
> </obj-entity>
> <db-relationship name="bases" source="A" target="Base" toMany="true">
> <db-attribute-pair source="A_ID" target="BASE_ID"/>
> </db-relationship>
>
> I thought that by adding this:
>
> <obj-relationship name="bases1" source="A" target="Base1" db-relationship-path="bases"/>,
>
> in other words: A -> B1,
>
> Then I would be able to do A.getBases1() to retrieve all of my subclasses instead of always having to go through A.getBases() and then filter using the discriminator column.
> But it is not working. Any idea how to achieve what I am trying to do?
> Thanks.
>

Re: many2many + single table inheritance

Posted by Ramiro Aparicio <ra...@prot-on.com>.
I have been working with inheritance a lot lately but finally I had to 
remove it from my model.

If Base is an abstract class you will have problems at deleting A o Base 
child objects.
Anyway in your case you want to make 3 relationships, A<-Base A->Base1 
A->Base2 (the arrows are not for cardinality just to tell where do you 
want to model the relationships) this will render some warnings or 
notices in the modeller, but will work ok with your current usage.

El 13/01/2013 13:46, emeka okafor escribió:
>
> Hello again,
> I have been trying to simplify some parts of my code and so I figured the following will work:
>
> I have a many-to-many relation, say A <<->> Base
> Base has two subclasses, say Base1 andBase2 modeled using single table inheritance,
> so basically:
> <obj-entity name="Base1" superEntityName="Base" className="Base1">
>
> <qualifier><![CDATA[Type = "BASE1"]]></qualifier>
> </obj-entity>
> <db-relationship name="bases" source="A" target="Base" toMany="true">
> <db-attribute-pair source="A_ID" target="BASE_ID"/>
> </db-relationship>
>
> I thought that by adding this:
>
> <obj-relationship name="bases1" source="A" target="Base1" db-relationship-path="bases"/>,
>
> in other words: A -> B1,
>
> Then I would be able to do A.getBases1() to retrieve all of my subclasses instead of always having to go through A.getBases() and then filter using the discriminator column.
> But it is not working. Any idea how to achieve what I am trying to do?
> Thanks.
>


many2many + single table inheritance

Posted by emeka okafor <em...@yahoo.com>.

Hello again,
I have been trying to simplify some parts of my code and so I figured the following will work:

I have a many-to-many relation, say A <<->> Base
Base has two subclasses, say Base1 andBase2 modeled using single table inheritance,
so basically:
<obj-entity name="Base1" superEntityName="Base" className="Base1">

<qualifier><![CDATA[Type = "BASE1"]]></qualifier>
</obj-entity>
<db-relationship name="bases" source="A" target="Base" toMany="true">
<db-attribute-pair source="A_ID" target="BASE_ID"/>
</db-relationship>

I thought that by adding this:

<obj-relationship name="bases1" source="A" target="Base1" db-relationship-path="bases"/>,

in other words: A -> B1, 

Then I would be able to do A.getBases1() to retrieve all of my subclasses instead of always having to go through A.getBases() and then filter using the discriminator column.
But it is not working. Any idea how to achieve what I am trying to do?
Thanks.

Re: testing many to many

Posted by Michael Gentry <mg...@masslight.net>.
Hi there,

You told Cayenne to delete the DataSource (datasource1) from the database,
but you didn't remove datasource1 from the object graph.  Cayenne usually
considers these separate operations*.  This is why you can still call:

System.out.println(blog1.getDatasources().get(0)); // prints datasource0
System.out.println(blog1.getDatasources().get(1)); // prints datasource1 <=
WHY?

Your datasource1 object is still in the object graph even though you
deleted it from the database.  Try adding something like
blog1.removeFromDatasources(blog1.getDatasources().get(1)) after your
deleteObjects call.

*The reason why Cayenne keeps remove/delete separate is because you may
want to remove a a DataSource from one Blog and attach it to another Blog.
 Also, sometimes you just want to unlink the Datasource, but not delete it.
 Therefore, you tell Cayenne explicitly to remove from the object graph and
to delete the object.

mrg

PS. I *think* you can put a Nullify delete rule from DataSource to Blog to
have it auto-remove (datasource1) from the object graph, but it has been
ages since I've tried that, so I most likely am wrong.  I personally prefer
to have both operations (remove and delete) explicitly stated in the code
so I can see exactly the intent there instead of having to look at two
different sources (code+model).



On Sat, Jan 5, 2013 at 8:12 AM, emeka okafor <em...@yahoo.com> wrote:

>  I stumbled across a weird thing today and believe that it has something
> to do with the fact that I am a cayenne newbie. Here is the situation:
>
> I have a many-to-many relationship: Blog <<=>> DataSource.
> I have configured it in the modeler the simplest way possible, without any
> specific relationship table and no flattened relation.
> I have this test snippet:
>
> System.out.println(blog1.getDatasources().get(0));
>            // prints datasource0
> System.out.println(blog1.getDatasources().get(1));
>            // prints datasouce1
>
> blog1.getObjectContext().deleteObjects(blog1.getDatasources().get(1));  //
> delete datasource1
> blog1.getObjectContext().commitChanges();
>            // commit changes
> System.out.println(blog1.getDatasources().get(0));
>             // prints datasource0
> System.out.println(blog1.getDatasources().get(1));
>             // prints datasource1 <= WHY?
> Assert.assertEquals(1, blog1.getDatasources().size());
>            // FAILS
>
> Am I doing something wrong here?
>
> Thanks.

testing many to many

Posted by emeka okafor <em...@yahoo.com>.
 I stumbled across a weird thing today and believe that it has something to do with the fact that I am a cayenne newbie. Here is the situation:

I have a many-to-many relationship: Blog <<=>> DataSource. 
I have configured it in the modeler the simplest way possible, without any specific relationship table and no flattened relation.
I have this test snippet: 

System.out.println(blog1.getDatasources().get(0));                                    // prints datasource0
System.out.println(blog1.getDatasources().get(1));                                    // prints datasouce1

blog1.getObjectContext().deleteObjects(blog1.getDatasources().get(1));  // delete datasource1
blog1.getObjectContext().commitChanges();                                            // commit changes
System.out.println(blog1.getDatasources().get(0));                                     // prints datasource0
System.out.println(blog1.getDatasources().get(1));                                     // prints datasource1 <= WHY?
Assert.assertEquals(1, blog1.getDatasources().size());                                // FAILS
 
Am I doing something wrong here?

Thanks.

Re: Deleting object rendes an instanciation exception

Posted by Ramiro Aparicio <ra...@prot-on.com>.
Hi Andrus,

Nop every row in the database (and thats about 180K rows) is from one 
type or another.
I am trying to find out why it has those relations and what entities are 
being cascaded into the delete, just in case I have the model misconfigured.

Ramiro

El 03/01/2013 19:16, Andrus Adamchik escribió:
> Hi Ramiro,
>
> Happy New Year to you too :)
>
> So is it possible that the database row that causes this exception does not map to any concrete subclass entity qualifier?
>
> Andrus
>
>
> On Jan 3, 2013, at 8:54 PM, Ramiro Aparicio <ra...@prot-on.com> wrote:
>
>> Hi and happy new year to everyone,
>>
>> I am back with my happy inheritance one more time.
>> I am using single table inheritance and just in case someone did not remember the model here is a simplification about it:
>>
>> abstract SessionLog it has relations to other tables as Log or User
>> SessionLogApi and SessionLogWeb that inherits from SessionLog they have specific information about the session type and their own relations
>>
>> I have found some problems with this kind of mapping but till now I have always find a way to hack around Cayenne problems with this and today (we are really near to put the new version with inheritance in production) I have struck against this exception:
>>
>> Caused by: org.apache.cayenne.CayenneRuntimeException: [v.3.1B1 May 28 2012 18:42:43] Error creating object of class 'com.proton.ks.persistence.SessionLog'
>> at org.apache.cayenne.reflect.PersistentDescriptor.createObject(PersistentDescriptor.java:288)
>> at org.apache.cayenne.reflect.LazyClassDescriptorDecorator.createObject(LazyClassDescriptorDecorator.java:73)
>> at org.apache.cayenne.access.DataContext.findOrCreateObject(DataContext.java:1178)
>> at org.apache.cayenne.access.ObjectResolver.objectFromDataRow(ObjectResolver.java:151)
>> at org.apache.cayenne.access.ObjectResolver.objectFromDataRow(ObjectResolver.java:137)
>> at org.apache.cayenne.access.ObjectResolver.objectsFromDataRows(ObjectResolver.java:121)
>> at org.apache.cayenne.access.ObjectResolver.synchronizedObjectsFromDataRows(ObjectResolver.java:102)
>> at org.apache.cayenne.access.ObjectResolver.synchronizedRootResultNodeFromDataRows(ObjectResolver.java:93)
>> at org.apache.cayenne.access.DataDomainQueryAction$ObjectConversionStrategy.toResultsTree(DataDomainQueryAction.java:581)
>> at org.apache.cayenne.access.DataDomainQueryAction$SingleObjectConversionStrategy.convert(DataDomainQueryAction.java:637)
>> at org.apache.cayenne.access.DataDomainQueryAction.interceptObjectConversion(DataDomainQueryAction.java:465)
>> at org.apache.cayenne.access.DataDomainQueryAction.execute(DataDomainQueryAction.java:129)
>> at org.apache.cayenne.access.DataDomain.onQueryNoFilters(DataDomain.java:754)
>> at org.apache.cayenne.access.DataDomain$DataDomainQueryFilterChain.onQuery(DataDomain.java:1003)
>> at org.apache.cayenne.access.DataDomain.onQuery(DataDomain.java:744)
>> at org.apache.cayenne.util.ObjectContextQueryAction.runQuery(ObjectContextQueryAction.java:350)
>> at org.apache.cayenne.util.ObjectContextQueryAction.executePostCache(ObjectContextQueryAction.java:106)
>> at org.apache.cayenne.util.ObjectContextQueryAction.execute(ObjectContextQueryAction.java:93)
>> at org.apache.cayenne.access.DataContext.onQuery(DataContext.java:989)
>> at org.apache.cayenne.access.DataContext.performQuery(DataContext.java:978)
>> at org.apache.cayenne.util.RelationshipFault.resolveFromDB(RelationshipFault.java:89)
>> at org.apache.cayenne.util.PersistentObjectList.resolvedObjectList(PersistentObjectList.java:301)
>> at org.apache.cayenne.util.PersistentObjectList.toArray(PersistentObjectList.java:278)
>> at java.util.ArrayList.(ArrayList.java:131)
>> at org.apache.cayenne.ObjectContextDeleteAction.toCollection(ObjectContextDeleteAction.java:124)
>> at org.apache.cayenne.ObjectContextDeleteAction.processDeleteRules(ObjectContextDeleteAction.java:153)
>> at org.apache.cayenne.ObjectContextDeleteAction.deletePersistent(ObjectContextDeleteAction.java:112)
>> at org.apache.cayenne.ObjectContextDeleteAction.performDelete(ObjectContextDeleteAction.java:91)
>> at org.apache.cayenne.BaseContext.deleteObjects(BaseContext.java:698)
>> at com.proton.cayenne.utils.CayenneTemplate.deleteObject(CayenneTemplate.java:79)
>> at com.proton.ks.services.business.HostingService.rejectUserRequestToDomain(SourceFile:413)
>> ... 120 more
>> Caused by: java.lang.InstantiationException
>> at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:30)
>> at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
>> at java.lang.Class.newInstance0(Class.java:355)
>> at java.lang.Class.newInstance(Class.java:308)
>> at org.apache.cayenne.reflect.PersistentDescriptor.createObject(PersistentDescriptor.java:285)
>> ... 150 more
>>
>> In case it is not clear in the trace I am only doing a context.deleteObjects(user) that user is cascading throught the model and in some way hitting a SessionLogApi or SessionLogWeb which Cayenne treats as a standard SessionLog and fails.
>>
>> I hope Andrus can help with this, at least with a way to circunvent the error as the fix, if feasible, will take some time to arrive a Cayenne release version.
>>
>> As always just ask for model, tests, or whatever as I am happy to provide them.
>>
>> Thank you in advance and merry christmas
>>


Re: Deleting object rendes an instanciation exception

Posted by Andrus Adamchik <an...@objectstyle.org>.
On Jan 4, 2013, at 6:54 PM, Ramiro Aparicio <ra...@prot-on.com> wrote:

> 
> And by the way I found what seems a Copy Paste error at performDelete inside ObjectContextDeleteAction, there is double call to "context.prepareForAccess(object, null, false);*" *

Ugh, appears to be a bad patch merge. Just fixed it. Thanks.

Andrus

Re: Deleting object rendes an instanciation exception

Posted by Ramiro Aparicio <ra...@prot-on.com>.
After some more testing I found I can avoid the exception in first 
instance but it will crash anyway.

The problem is deleting a User with some related SessionLogWeb

SessionLog has a relationship with User to be able to find the user 
logged and the back relationship was modeled from User to SessionLog 
(abstract) with Cascade.

So deleting User triggers a delete on all SessionLog related and to 
verify the cascade rules of that element it tries to instanciate it.

So I changed the model to remove that back relationship and instead have 
2 backs relationship with SessionLogApi and SessionLogWeb, this 
generates a warning about discouraged back relationships... but allows 
to progress in the cascade but just to fail a couple of levels later.
SessionLog is related with User and with ActivityLog and ActivityLog has 
the same problem it has 3 back relationships (to SessionLog, 
SessionLogApi and SessionLogWeb) to avoid problems I setted 
ActivityLog->SessionLog as No action and left the other two as cascade,
as now it does not have any relationship requiring deleting a SessionLog 
everything should be ok..... but no.
As SessionLog is related with ActivityLog it tries to remove the object 
from the back relationship and thus generates and instance exception.

Caused by: org.apache.cayenne.reflect.PropertyException: [v.3.1B1 May 28 
2012 18:42:43] Error unsetting to-many DataObject property: activityArray
     at 
org.apache.cayenne.reflect.generic.DataObjectToManyProperty.removeTarget(DataObjectToManyProperty.java:91)
     at 
org.apache.cayenne.ObjectContextDeleteAction$1.visitToMany(ObjectContextDeleteAction.java:206)
     at 
org.apache.cayenne.reflect.generic.DataObjectToManyProperty.visit(DataObjectToManyProperty.java:111)
     at 
org.apache.cayenne.ObjectContextDeleteAction.processDeleteRules(ObjectContextDeleteAction.java:196)
     at 
org.apache.cayenne.ObjectContextDeleteAction.deletePersistent(ObjectContextDeleteAction.java:112)
     at 
org.apache.cayenne.ObjectContextDeleteAction.performDelete(ObjectContextDeleteAction.java:91)
     at 
org.apache.cayenne.ObjectContextDeleteAction.processDeleteRules(ObjectContextDeleteAction.java:230)
     at 
org.apache.cayenne.ObjectContextDeleteAction.deletePersistent(ObjectContextDeleteAction.java:112)
     at 
org.apache.cayenne.ObjectContextDeleteAction.performDelete(ObjectContextDeleteAction.java:91)
     at org.apache.cayenne.BaseContext.deleteObjects(BaseContext.java:712)
     at 
com.proton.cayenne.utils.CayenneTemplate.deleteObjects(CayenneTemplate.java:84)
     at 
com.proton.ks.services.business.HostingService.rejectUserRequestToDomain(HostingService.java:414)
     ... 119 more
Caused by: org.apache.cayenne.CayenneRuntimeException: [v.3.1B1 May 28 
2012 18:42:43] Error creating object of class 
'com.proton.ks.persistence.SessionLog'
     at 
org.apache.cayenne.reflect.PersistentDescriptor.createObject(PersistentDescriptor.java:288)
     at 
org.apache.cayenne.reflect.LazyClassDescriptorDecorator.createObject(LazyClassDescriptorDecorator.java:73)
     at 
org.apache.cayenne.access.DataContext.findOrCreateObject(DataContext.java:1178)
     at 
org.apache.cayenne.access.ObjectResolver.objectFromDataRow(ObjectResolver.java:151)
     at 
org.apache.cayenne.access.ObjectResolver.objectFromDataRow(ObjectResolver.java:137)
     at 
org.apache.cayenne.access.ObjectResolver.objectsFromDataRows(ObjectResolver.java:121)
     at 
org.apache.cayenne.access.ObjectResolver.synchronizedObjectsFromDataRows(ObjectResolver.java:102)
     at 
org.apache.cayenne.access.ObjectResolver.synchronizedRootResultNodeFromDataRows(ObjectResolver.java:93)
     at 
org.apache.cayenne.access.DataDomainQueryAction$ObjectConversionStrategy.toResultsTree(DataDomainQueryAction.java:581)
     at 
org.apache.cayenne.access.DataDomainQueryAction$SingleObjectConversionStrategy.convert(DataDomainQueryAction.java:637)
     at 
org.apache.cayenne.access.DataDomainQueryAction.interceptObjectConversion(DataDomainQueryAction.java:465)
     at 
org.apache.cayenne.access.DataDomainQueryAction.execute(DataDomainQueryAction.java:129)
     at 
org.apache.cayenne.access.DataDomain.onQueryNoFilters(DataDomain.java:754)
     at 
org.apache.cayenne.access.DataDomain$DataDomainQueryFilterChain.onQuery(DataDomain.java:1003)
     at org.apache.cayenne.access.DataDomain.onQuery(DataDomain.java:744)
     at 
org.apache.cayenne.util.ObjectContextQueryAction.runQuery(ObjectContextQueryAction.java:350)
     at 
org.apache.cayenne.util.ObjectContextQueryAction.executePostCache(ObjectContextQueryAction.java:106)
     at 
org.apache.cayenne.util.ObjectContextQueryAction.execute(ObjectContextQueryAction.java:93)
     at org.apache.cayenne.access.DataContext.onQuery(DataContext.java:989)
     at 
org.apache.cayenne.access.DataContext.performQuery(DataContext.java:978)
     at 
org.apache.cayenne.access.ToOneFault.doResolveFault(ToOneFault.java:81)
     at 
org.apache.cayenne.access.ToOneFault.resolveFault(ToOneFault.java:54)
     at 
org.apache.cayenne.CayenneDataObject.readProperty(CayenneDataObject.java:186)
     at 
org.apache.cayenne.CayenneDataObject.setToOneTarget(CayenneDataObject.java:273)
     at 
org.apache.cayenne.CayenneDataObject.unsetReverseRelationship(CayenneDataObject.java:363)
     at 
org.apache.cayenne.CayenneDataObject.removeToManyTarget(CayenneDataObject.java:234)
     at 
org.apache.cayenne.reflect.generic.DataObjectToManyProperty.removeTarget(DataObjectToManyProperty.java:85)
     ... 130 more
Caused by: java.lang.InstantiationException
     at 
sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(Unknown 
Source)
     at java.lang.reflect.Constructor.newInstance(Unknown Source)
     at java.lang.Class.newInstance0(Unknown Source)
     at java.lang.Class.newInstance(Unknown Source)
     at 
org.apache.cayenne.reflect.PersistentDescriptor.createObject(PersistentDescriptor.java:285)
     ... 156 more

I think that removing the back relationship from ActivityLog to 
SessionLog can avoid the error, but I need to use that in some queries 
to filter and order by User (that is a shared relationship between both 
Entities).

My model can be checked at: http://db.tt/XRtJcNoL

I will try to find a workaround about this and the only way is not 
creating related entities unless I am 100% sure the object will not be 
deleted (in this case I think I can do that but it is a rare exception).

As things are now the abstract checkbox at Cayenne Modeller should be 
removed or at least forbid creating relationship from or to abstract 
entities.
The only fix I can think of is that createObject of PersistentDescriptor 
should check if the class is abstract or not before trying to 
instanciate it and if it is instanciate the correct subclass y possible, 
but I see no way how you can identify the correct subclass with only the 
ObjectId


And by the way I found what seems a Copy Paste error at performDelete 
inside ObjectContextDeleteAction, there is double call to 
"context.prepareForAccess(object, null, false);*" *

Ramiro


El 03/01/2013 19:16, Andrus Adamchik escribió:
> Hi Ramiro,
>
> Happy New Year to you too :)
>
> So is it possible that the database row that causes this exception does not map to any concrete subclass entity qualifier?
>
> Andrus
>
>
> On Jan 3, 2013, at 8:54 PM, Ramiro Aparicio <ra...@prot-on.com> wrote:
>
>> Hi and happy new year to everyone,
>>
>> I am back with my happy inheritance one more time.
>> I am using single table inheritance and just in case someone did not remember the model here is a simplification about it:
>>
>> abstract SessionLog it has relations to other tables as Log or User
>> SessionLogApi and SessionLogWeb that inherits from SessionLog they have specific information about the session type and their own relations
>>
>> I have found some problems with this kind of mapping but till now I have always find a way to hack around Cayenne problems with this and today (we are really near to put the new version with inheritance in production) I have struck against this exception:
>>
>> Caused by: org.apache.cayenne.CayenneRuntimeException: [v.3.1B1 May 28 2012 18:42:43] Error creating object of class 'com.proton.ks.persistence.SessionLog'
>> at org.apache.cayenne.reflect.PersistentDescriptor.createObject(PersistentDescriptor.java:288)
>> at org.apache.cayenne.reflect.LazyClassDescriptorDecorator.createObject(LazyClassDescriptorDecorator.java:73)
>> at org.apache.cayenne.access.DataContext.findOrCreateObject(DataContext.java:1178)
>> at org.apache.cayenne.access.ObjectResolver.objectFromDataRow(ObjectResolver.java:151)
>> at org.apache.cayenne.access.ObjectResolver.objectFromDataRow(ObjectResolver.java:137)
>> at org.apache.cayenne.access.ObjectResolver.objectsFromDataRows(ObjectResolver.java:121)
>> at org.apache.cayenne.access.ObjectResolver.synchronizedObjectsFromDataRows(ObjectResolver.java:102)
>> at org.apache.cayenne.access.ObjectResolver.synchronizedRootResultNodeFromDataRows(ObjectResolver.java:93)
>> at org.apache.cayenne.access.DataDomainQueryAction$ObjectConversionStrategy.toResultsTree(DataDomainQueryAction.java:581)
>> at org.apache.cayenne.access.DataDomainQueryAction$SingleObjectConversionStrategy.convert(DataDomainQueryAction.java:637)
>> at org.apache.cayenne.access.DataDomainQueryAction.interceptObjectConversion(DataDomainQueryAction.java:465)
>> at org.apache.cayenne.access.DataDomainQueryAction.execute(DataDomainQueryAction.java:129)
>> at org.apache.cayenne.access.DataDomain.onQueryNoFilters(DataDomain.java:754)
>> at org.apache.cayenne.access.DataDomain$DataDomainQueryFilterChain.onQuery(DataDomain.java:1003)
>> at org.apache.cayenne.access.DataDomain.onQuery(DataDomain.java:744)
>> at org.apache.cayenne.util.ObjectContextQueryAction.runQuery(ObjectContextQueryAction.java:350)
>> at org.apache.cayenne.util.ObjectContextQueryAction.executePostCache(ObjectContextQueryAction.java:106)
>> at org.apache.cayenne.util.ObjectContextQueryAction.execute(ObjectContextQueryAction.java:93)
>> at org.apache.cayenne.access.DataContext.onQuery(DataContext.java:989)
>> at org.apache.cayenne.access.DataContext.performQuery(DataContext.java:978)
>> at org.apache.cayenne.util.RelationshipFault.resolveFromDB(RelationshipFault.java:89)
>> at org.apache.cayenne.util.PersistentObjectList.resolvedObjectList(PersistentObjectList.java:301)
>> at org.apache.cayenne.util.PersistentObjectList.toArray(PersistentObjectList.java:278)
>> at java.util.ArrayList.(ArrayList.java:131)
>> at org.apache.cayenne.ObjectContextDeleteAction.toCollection(ObjectContextDeleteAction.java:124)
>> at org.apache.cayenne.ObjectContextDeleteAction.processDeleteRules(ObjectContextDeleteAction.java:153)
>> at org.apache.cayenne.ObjectContextDeleteAction.deletePersistent(ObjectContextDeleteAction.java:112)
>> at org.apache.cayenne.ObjectContextDeleteAction.performDelete(ObjectContextDeleteAction.java:91)
>> at org.apache.cayenne.BaseContext.deleteObjects(BaseContext.java:698)
>> at com.proton.cayenne.utils.CayenneTemplate.deleteObject(CayenneTemplate.java:79)
>> at com.proton.ks.services.business.HostingService.rejectUserRequestToDomain(SourceFile:413)
>> ... 120 more
>> Caused by: java.lang.InstantiationException
>> at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:30)
>> at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
>> at java.lang.Class.newInstance0(Class.java:355)
>> at java.lang.Class.newInstance(Class.java:308)
>> at org.apache.cayenne.reflect.PersistentDescriptor.createObject(PersistentDescriptor.java:285)
>> ... 150 more
>>
>> In case it is not clear in the trace I am only doing a context.deleteObjects(user) that user is cascading throught the model and in some way hitting a SessionLogApi or SessionLogWeb which Cayenne treats as a standard SessionLog and fails.
>>
>> I hope Andrus can help with this, at least with a way to circunvent the error as the fix, if feasible, will take some time to arrive a Cayenne release version.
>>
>> As always just ask for model, tests, or whatever as I am happy to provide them.
>>
>> Thank you in advance and merry christmas
>>


Re: Deleting object rendes an instanciation exception

Posted by Andrus Adamchik <an...@objectstyle.org>.
Hi Ramiro,

Happy New Year to you too :)

So is it possible that the database row that causes this exception does not map to any concrete subclass entity qualifier? 

Andrus


On Jan 3, 2013, at 8:54 PM, Ramiro Aparicio <ra...@prot-on.com> wrote:

> Hi and happy new year to everyone,
> 
> I am back with my happy inheritance one more time.
> I am using single table inheritance and just in case someone did not remember the model here is a simplification about it:
> 
> abstract SessionLog it has relations to other tables as Log or User
> SessionLogApi and SessionLogWeb that inherits from SessionLog they have specific information about the session type and their own relations
> 
> I have found some problems with this kind of mapping but till now I have always find a way to hack around Cayenne problems with this and today (we are really near to put the new version with inheritance in production) I have struck against this exception:
> 
> Caused by: org.apache.cayenne.CayenneRuntimeException: [v.3.1B1 May 28 2012 18:42:43] Error creating object of class 'com.proton.ks.persistence.SessionLog'
> at org.apache.cayenne.reflect.PersistentDescriptor.createObject(PersistentDescriptor.java:288)
> at org.apache.cayenne.reflect.LazyClassDescriptorDecorator.createObject(LazyClassDescriptorDecorator.java:73)
> at org.apache.cayenne.access.DataContext.findOrCreateObject(DataContext.java:1178)
> at org.apache.cayenne.access.ObjectResolver.objectFromDataRow(ObjectResolver.java:151)
> at org.apache.cayenne.access.ObjectResolver.objectFromDataRow(ObjectResolver.java:137)
> at org.apache.cayenne.access.ObjectResolver.objectsFromDataRows(ObjectResolver.java:121)
> at org.apache.cayenne.access.ObjectResolver.synchronizedObjectsFromDataRows(ObjectResolver.java:102)
> at org.apache.cayenne.access.ObjectResolver.synchronizedRootResultNodeFromDataRows(ObjectResolver.java:93)
> at org.apache.cayenne.access.DataDomainQueryAction$ObjectConversionStrategy.toResultsTree(DataDomainQueryAction.java:581)
> at org.apache.cayenne.access.DataDomainQueryAction$SingleObjectConversionStrategy.convert(DataDomainQueryAction.java:637)
> at org.apache.cayenne.access.DataDomainQueryAction.interceptObjectConversion(DataDomainQueryAction.java:465)
> at org.apache.cayenne.access.DataDomainQueryAction.execute(DataDomainQueryAction.java:129)
> at org.apache.cayenne.access.DataDomain.onQueryNoFilters(DataDomain.java:754)
> at org.apache.cayenne.access.DataDomain$DataDomainQueryFilterChain.onQuery(DataDomain.java:1003)
> at org.apache.cayenne.access.DataDomain.onQuery(DataDomain.java:744)
> at org.apache.cayenne.util.ObjectContextQueryAction.runQuery(ObjectContextQueryAction.java:350)
> at org.apache.cayenne.util.ObjectContextQueryAction.executePostCache(ObjectContextQueryAction.java:106)
> at org.apache.cayenne.util.ObjectContextQueryAction.execute(ObjectContextQueryAction.java:93)
> at org.apache.cayenne.access.DataContext.onQuery(DataContext.java:989)
> at org.apache.cayenne.access.DataContext.performQuery(DataContext.java:978)
> at org.apache.cayenne.util.RelationshipFault.resolveFromDB(RelationshipFault.java:89)
> at org.apache.cayenne.util.PersistentObjectList.resolvedObjectList(PersistentObjectList.java:301)
> at org.apache.cayenne.util.PersistentObjectList.toArray(PersistentObjectList.java:278)
> at java.util.ArrayList.(ArrayList.java:131)
> at org.apache.cayenne.ObjectContextDeleteAction.toCollection(ObjectContextDeleteAction.java:124)
> at org.apache.cayenne.ObjectContextDeleteAction.processDeleteRules(ObjectContextDeleteAction.java:153)
> at org.apache.cayenne.ObjectContextDeleteAction.deletePersistent(ObjectContextDeleteAction.java:112)
> at org.apache.cayenne.ObjectContextDeleteAction.performDelete(ObjectContextDeleteAction.java:91)
> at org.apache.cayenne.BaseContext.deleteObjects(BaseContext.java:698)
> at com.proton.cayenne.utils.CayenneTemplate.deleteObject(CayenneTemplate.java:79)
> at com.proton.ks.services.business.HostingService.rejectUserRequestToDomain(SourceFile:413)
> ... 120 more
> Caused by: java.lang.InstantiationException
> at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:30)
> at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
> at java.lang.Class.newInstance0(Class.java:355)
> at java.lang.Class.newInstance(Class.java:308)
> at org.apache.cayenne.reflect.PersistentDescriptor.createObject(PersistentDescriptor.java:285)
> ... 150 more
> 
> In case it is not clear in the trace I am only doing a context.deleteObjects(user) that user is cascading throught the model and in some way hitting a SessionLogApi or SessionLogWeb which Cayenne treats as a standard SessionLog and fails.
> 
> I hope Andrus can help with this, at least with a way to circunvent the error as the fix, if feasible, will take some time to arrive a Cayenne release version.
> 
> As always just ask for model, tests, or whatever as I am happy to provide them.
> 
> Thank you in advance and merry christmas
>