Erratic AshwoodEntitySorter NPE on Latest Snapshot

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Erratic AshwoodEntitySorter NPE on Latest Snapshot

fael
I'm using Cayenne for my Tapestry web apps - all run on the same version of Jetty both locally when debugging and live. On occasion - when I deploy a war file to the live server - a 'random' database insert will cause exactly the following exception to occur. I could then change any irrelevant thing (add white-space to a mark-up file for example) and re-deploy the war and this exception will just go away.

It also seems to have the potential to occur only on a single random commit (always on insertions). But only on one per deployment. Other inserts will work fine - even the exact same code will work fine on a different web-app deployed in exactly the same way to an identical live server.

I was wondering if anyone else may have experienced this? I haven't been able to figure out the root of it over the past month or so experiencing it using the latest snapshot of Cayenne. Sometimes it happens, sometimes it doesn't and only when packaged in a WAR and deployed to my live Jetty server.

If there's any other info I could provide that would lead to any conclusions please do let me know!

Caused by: java.lang.NullPointerException
at org.apache.cayenne.ashwood.AshwoodEntitySorter$DbEntityComparator.compare(AshwoodEntitySorter.java:364)
at org.apache.cayenne.ashwood.AshwoodEntitySorter$DbEntityComparator.compare(AshwoodEntitySorter.java:351)
at java.util.TimSort.countRunAndMakeAscending(TimSort.java:355)
at java.util.TimSort.sort(TimSort.java:220)
at java.util.Arrays.sort(Arrays.java:1512)
at java.util.ArrayList.sort(ArrayList.java:1454)
at java.util.Collections.sort(Collections.java:175)
at org.apache.cayenne.ashwood.AshwoodEntitySorter.sortDbEntities(AshwoodEntitySorter.java:182)
at com.jamesinnes.web.services.MyAshwoodEntitySorter.sortDbEntities(MyAshwoodEntitySorter.java:19)
at org.apache.cayenne.access.DataDomainInsertBucket.appendQueriesInternal(DataDomainInsertBucket.java:56)
at org.apache.cayenne.access.DataDomainSyncBucket.appendQueries(DataDomainSyncBucket.java:78)
at org.apache.cayenne.access.DataDomainFlushAction.preprocess(DataDomainFlushAction.java:189)
at org.apache.cayenne.access.DataDomainFlushAction.flush(DataDomainFlushAction.java:145)
at org.apache.cayenne.access.DataDomain.onSyncFlush(DataDomain.java:629)
at org.apache.cayenne.access.DataDomain.onSyncNoFilters(DataDomain.java:598)
at org.apache.cayenne.access.DataDomain$DataDomainSyncFilterChain.onSync(DataDomain.java:746)
at org.apache.cayenne.tx.TransactionFilter$1.perform(TransactionFilter.java:73)
at org.apache.cayenne.tx.TransactionFilter$1.perform(TransactionFilter.java:70)
at org.apache.cayenne.tx.DefaultTransactionManager.performInTransaction(DefaultTransactionManager.java:53)
at org.apache.cayenne.tx.TransactionFilter.onSync(TransactionFilter.java:70)
at org.apache.cayenne.access.DataDomain$DataDomainSyncFilterChain.onSync(DataDomain.java:746)
at org.apache.cayenne.access.DataDomain.onSync(DataDomain.java:585)
at org.apache.cayenne.access.DataContext.flushToParent(DataContext.java:744)
... 121 more

Thanks!
Peter
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Erratic AshwoodEntitySorter NPE on Latest Snapshot

Andrus Adamchik
Hi Peter,

I've never seen this particular error. Wonder if there's some race condition involved. There were some recent refactorings done to AshwoodEntitySorter. Wonder if those somehow messed it up. Would you be able to rebuild Cayenne 4.0 using a revision older than Nov 16 80de06e8f0424daf7145ddbd95c3dd7a0cfeca2d (e.g. this one: e0caeacb1db20ead138ff7bad08cc48b40417ee6) and see if it keep happening?

Thanks,
Andrus


> On Feb 1, 2016, at 11:56 AM, fael <[hidden email]> wrote:
>
> I'm using Cayenne for my Tapestry web apps - all run on the same version of
> Jetty both locally when debugging and live. On occasion - when I deploy a
> war file to the live server - a 'random' database insert will cause exactly
> the following exception to occur. I could then change any irrelevant thing
> (add white-space to a mark-up file for example) and re-deploy the war and
> this exception will just go away.
>
> It also seems to have the potential to occur only on a single random commit
> (always on insertions). But only on one per deployment. Other inserts will
> work fine - even the exact same code will work fine on a different web-app
> deployed in exactly the same way to an identical live server.
>
> I was wondering if anyone else may have experienced this? I haven't been
> able to figure out the root of it over the past month or so experiencing it
> using the latest snapshot of Cayenne. Sometimes it happens, sometimes it
> doesn't and only when packaged in a WAR and deployed to my live Jetty
> server.
>
> If there's any other info I could provide that would lead to any conclusions
> please do let me know!
>
> Caused by: java.lang.NullPointerException
> at
> org.apache.cayenne.ashwood.AshwoodEntitySorter$DbEntityComparator.compare(AshwoodEntitySorter.java:364)
> at
> org.apache.cayenne.ashwood.AshwoodEntitySorter$DbEntityComparator.compare(AshwoodEntitySorter.java:351)
> at java.util.TimSort.countRunAndMakeAscending(TimSort.java:355)
> at java.util.TimSort.sort(TimSort.java:220)
> at java.util.Arrays.sort(Arrays.java:1512)
> at java.util.ArrayList.sort(ArrayList.java:1454)
> at java.util.Collections.sort(Collections.java:175)
> at
> org.apache.cayenne.ashwood.AshwoodEntitySorter.sortDbEntities(AshwoodEntitySorter.java:182)
> at
> com.jamesinnes.web.services.MyAshwoodEntitySorter.sortDbEntities(MyAshwoodEntitySorter.java:19)
> at
> org.apache.cayenne.access.DataDomainInsertBucket.appendQueriesInternal(DataDomainInsertBucket.java:56)
> at
> org.apache.cayenne.access.DataDomainSyncBucket.appendQueries(DataDomainSyncBucket.java:78)
> at
> org.apache.cayenne.access.DataDomainFlushAction.preprocess(DataDomainFlushAction.java:189)
> at
> org.apache.cayenne.access.DataDomainFlushAction.flush(DataDomainFlushAction.java:145)
> at org.apache.cayenne.access.DataDomain.onSyncFlush(DataDomain.java:629)
> at org.apache.cayenne.access.DataDomain.onSyncNoFilters(DataDomain.java:598)
> at
> org.apache.cayenne.access.DataDomain$DataDomainSyncFilterChain.onSync(DataDomain.java:746)
> at
> org.apache.cayenne.tx.TransactionFilter$1.perform(TransactionFilter.java:73)
> at
> org.apache.cayenne.tx.TransactionFilter$1.perform(TransactionFilter.java:70)
> at
> org.apache.cayenne.tx.DefaultTransactionManager.performInTransaction(DefaultTransactionManager.java:53)
> at org.apache.cayenne.tx.TransactionFilter.onSync(TransactionFilter.java:70)
> at
> org.apache.cayenne.access.DataDomain$DataDomainSyncFilterChain.onSync(DataDomain.java:746)
> at org.apache.cayenne.access.DataDomain.onSync(DataDomain.java:585)
> at org.apache.cayenne.access.DataContext.flushToParent(DataContext.java:744)
> ... 121 more
>
> Thanks!
> Peter
>
>
>
> --
> View this message in context: http://cayenne.195.n3.nabble.com/Erratic-AshwoodEntitySorter-NPE-on-Latest-Snapshot-tp4027453.html
> Sent from the Cayenne - User mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Erratic AshwoodEntitySorter NPE on Latest Snapshot

fael
Hello,

I'm really sorry for how long it took to respond to this - sadly did not have time to look into it further due to time constraints at work.

The problem still exhibits itself - I've rebuilt Cayenne 4 a couple of times - I'm also seeing it manifest with the following exception:

Caused by: org.apache.cayenne.CayenneRuntimeException: [v.4.0.M3-SNAPSHOT Jan 12 2016 15:08:09] Can't extract a master key. Missing key (id), master ID ()
at org.apache.cayenne.access.DataDomainSyncBucket$PropagatedValueFactory.create(DataDomainSyncBucket.java:311)
at org.apache.cayenne.query.BatchQueryRow.getValue(BatchQueryRow.java:64)
at org.apache.cayenne.query.InsertBatchQuery$1.getValue(InsertBatchQuery.java:64)
at org.apache.cayenne.access.translator.batch.InsertBatchTranslator.doUpdateBindings(InsertBatchTranslator.java:119)
at org.apache.cayenne.access.translator.batch.DefaultBatchTranslator.updateBindings(DefaultBatchTranslator.java:78)
at org.apache.cayenne.access.jdbc.BatchAction.runAsIndividualQueries(BatchAction.java:169)
at org.apache.cayenne.access.jdbc.BatchAction.performAction(BatchAction.java:92)
at org.apache.cayenne.access.DataNodeQueryAction.runQuery(DataNodeQueryAction.java:97)
at org.apache.cayenne.access.DataNode.performQueries(DataNode.java:306)
at org.apache.cayenne.access.DataDomainFlushAction.runQueries(DataDomainFlushAction.java:234)
at org.apache.cayenne.access.DataDomainFlushAction.flush(DataDomainFlushAction.java:155)
at org.apache.cayenne.access.DataDomain.onSyncFlush(DataDomain.java:629)
at org.apache.cayenne.access.DataDomain.onSyncNoFilters(DataDomain.java:598)
at org.apache.cayenne.access.DataDomain$DataDomainSyncFilterChain.onSync(DataDomain.java:746)
at org.apache.cayenne.tx.TransactionFilter$1.perform(TransactionFilter.java:73)
at org.apache.cayenne.tx.TransactionFilter$1.perform(TransactionFilter.java:70)
at org.apache.cayenne.tx.DefaultTransactionManager.performInTransaction(DefaultTransactionManager.java:53)
at org.apache.cayenne.tx.TransactionFilter.onSync(TransactionFilter.java:70)
at org.apache.cayenne.access.DataDomain$DataDomainSyncFilterChain.onSync(DataDomain.java:746)
at org.apache.cayenne.access.DataDomain.onSync(DataDomain.java:585)
at org.apache.cayenne.access.DataContext.flushToParent(DataContext.java:744)
at org.apache.cayenne.access.DataContext.commitChanges(DataContext.java:693)
at com.jamesinnes.web.services.ShopServiceImpl.registerNewClient(ShopServiceImpl.java:358)

Have seen a few people getting this after searching the mailing list - I'm wondering whether writing my own entity sorter might be the quickest route to a fix as soon as I can dedicate some time to it!

It occurred to me that others may have their own implementations of Ashwood or other entity sorters - anyone up for sharing?

Or perhaps has there been any news as regards a potential fix for this?

Thanks all!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Erratic AshwoodEntitySorter NPE on Latest Snapshot

Aristedes Maniatis-2
On 25/10/16 6:22am, fael wrote:
> The problem still exhibits itself - I've rebuilt Cayenne 4 a couple of times
> - I'm also seeing it manifest with the following exception:

Does the problem go away with an older version of Cayenne, such as the last 4.0M3 release?

Ari


--
-------------------------->
Aristedes Maniatis
GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Erratic AshwoodEntitySorter NPE on Latest Snapshot

fael
Hi Ari,

I have never actually tried running on 4.0.M3 - have been on a 4.0.M3-SNAPSHOT that I built a couple times earlier in the year.

I experienced the problem on 4.0.M2 and my 4.0.M3-SNAPSHOT builds - specifically with Cayenne auto_pk_support it manifested as a NPE.

I recently switched to database-generated keys and this now manifests as the 'Master Key' error I mentioned in my last post.

It appears to be exactly the same issue - attempting to insert a child before its parent has been inserted (thus having a primary key to satisfy the child's foreign key constraint).

The issue occurs very infrequently when I'm running my web apps locally and far more frequently (almost every time) I deploy to my production server. This has me constantly re-deploying, rolling the dice, to get lucky and not experience the issue.

Locally I'm on Windows 10 64-bit, Oracle Java 8 64-bit (latest JRE + JDK), Jetty 8.1.14.v20131031.

On production it's Amazon Web Services' Elastic Beanstalk - Tomcat container - so that's Amazon Linux, Tomcat 8 and Java 8. I also saw it occurring quite frequently on Ubuntu Server 14.04, Jetty 9 and OpenJDK 8.

It seems to happen more frequently now I'm using database-generated primary keys.

As per your suggestion - I will try deploy to production using 4.0.M3 and report back with more info.

Thanks again!
Peter
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Erratic AshwoodEntitySorter NPE on Latest Snapshot

fael
Just have an update here - with M3 I am still experiencing a very random occurrence of the following exception still.

First of all - when the webapp is run in Jetty or Tomcat (versions/OS don't seem to have an effect at all) there is a roll of the dice as to whether 'Can't extract a master key' will rear its ugly head.

Secondly - when it does rear its ugly head there is a further roll of the dice for which insert it occurs on - though it will always occur.

This is really making patching and testing a proper nightmare - as such I wondered if anyone else was experiencing this or could shed light on a workaround or fix.

Stack Trace:
org.apache.cayenne.CayenneRuntimeException: [v.4.0.M3 Feb 08 2016 16:38:05] Can't extract a master key. Missing key (id), master ID ()
at org.apache.cayenne.access.DataDomainSyncBucket$PropagatedValueFactory.create(DataDomainSyncBucket.java:311)
at org.apache.cayenne.query.BatchQueryRow.getValue(BatchQueryRow.java:64)
at org.apache.cayenne.query.InsertBatchQuery$1.getValue(InsertBatchQuery.java:64)
at org.apache.cayenne.access.translator.batch.InsertBatchTranslator.doUpdateBindings(InsertBatchTranslator.java:119)
at org.apache.cayenne.access.translator.batch.DefaultBatchTranslator.updateBindings(DefaultBatchTranslator.java:78)
at org.apache.cayenne.access.jdbc.BatchAction.runAsIndividualQueries(BatchAction.java:169)
at org.apache.cayenne.access.jdbc.BatchAction.performAction(BatchAction.java:92)
at org.apache.cayenne.access.DataNodeQueryAction.runQuery(DataNodeQueryAction.java:97)
at org.apache.cayenne.access.DataNode.performQueries(DataNode.java:306)
at org.apache.cayenne.access.DataDomainFlushAction.runQueries(DataDomainFlushAction.java:234)
at org.apache.cayenne.access.DataDomainFlushAction.flush(DataDomainFlushAction.java:155)
at org.apache.cayenne.access.DataDomain.onSyncFlush(DataDomain.java:629)
at org.apache.cayenne.access.DataDomain.onSyncNoFilters(DataDomain.java:598)
at org.apache.cayenne.access.DataDomain$DataDomainSyncFilterChain.onSync(DataDomain.java:746)
at org.apache.cayenne.tx.TransactionFilter$1.perform(TransactionFilter.java:73)
at org.apache.cayenne.tx.TransactionFilter$1.perform(TransactionFilter.java:70)
at org.apache.cayenne.tx.DefaultTransactionManager.performInTransaction(DefaultTransactionManager.java:53)
at org.apache.cayenne.tx.TransactionFilter.onSync(TransactionFilter.java:70)
at org.apache.cayenne.access.DataDomain$DataDomainSyncFilterChain.onSync(DataDomain.java:746)
at org.apache.cayenne.access.DataDomain.onSync(DataDomain.java:585)
at org.apache.cayenne.access.DataContext.flushToParent(DataContext.java:744)
at org.apache.cayenne.access.DataContext.commitChanges(DataContext.java:693)
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Erratic AshwoodEntitySorter NPE on Latest Snapshot

Michael Gentry-2
Hi Peter,

This may or may not be helpful, but years ago we were getting the "roll of
the dice" issue with Ashwood as well.  We'd restart the application and the
insert error would occur in a different place.  It turns out someone had
created a circular object graph in our model and it gave Ashwood fits and
took us a while to debug.  The graph was akin to:

A -> B -> C -> D -> E -> A

Ashwood couldn't figure out a proper insert order (there isn't one with
DB-generated keys) and we were getting random failures until we cut the E
-> A relationship and then it started working again.

mrg


On Thu, Dec 8, 2016 at 7:25 AM, fael <[hidden email]> wrote:

> Just have an update here - with M3 I am still experiencing a very random
> occurrence of the following exception still.
>
> First of all - when the webapp is run in Jetty or Tomcat (versions/OS don't
> seem to have an effect at all) there is a roll of the dice as to whether
> 'Can't extract a master key' will rear its ugly head.
>
> Secondly - when it does rear its ugly head there is a further roll of the
> dice for which insert it occurs on - though it will always occur.
>
> This is really making patching and testing a proper nightmare - as such I
> wondered if anyone else was experiencing this or could shed light on a
> workaround or fix.
>
> Stack Trace:
> org.apache.cayenne.CayenneRuntimeException: [v.4.0.M3 Feb 08 2016
> 16:38:05]
> Can't extract a master key. Missing key (id), master ID ()
> at
> org.apache.cayenne.access.DataDomainSyncBucket$
> PropagatedValueFactory.create(DataDomainSyncBucket.java:311)
> at org.apache.cayenne.query.BatchQueryRow.getValue(BatchQueryRow.java:64)
> at
> org.apache.cayenne.query.InsertBatchQuery$1.getValue(
> InsertBatchQuery.java:64)
> at
> org.apache.cayenne.access.translator.batch.InsertBatchTranslator.
> doUpdateBindings(InsertBatchTranslator.java:119)
> at
> org.apache.cayenne.access.translator.batch.DefaultBatchTranslator.
> updateBindings(DefaultBatchTranslator.java:78)
> at
> org.apache.cayenne.access.jdbc.BatchAction.runAsIndividualQueries(
> BatchAction.java:169)
> at
> org.apache.cayenne.access.jdbc.BatchAction.performAction(BatchAction.
> java:92)
> at
> org.apache.cayenne.access.DataNodeQueryAction.runQuery(
> DataNodeQueryAction.java:97)
> at org.apache.cayenne.access.DataNode.performQueries(DataNode.java:306)
> at
> org.apache.cayenne.access.DataDomainFlushAction.runQueries(
> DataDomainFlushAction.java:234)
> at
> org.apache.cayenne.access.DataDomainFlushAction.flush(
> DataDomainFlushAction.java:155)
> at org.apache.cayenne.access.DataDomain.onSyncFlush(DataDomain.java:629)
> at org.apache.cayenne.access.DataDomain.onSyncNoFilters(
> DataDomain.java:598)
> at
> org.apache.cayenne.access.DataDomain$DataDomainSyncFilterChain.
> onSync(DataDomain.java:746)
> at
> org.apache.cayenne.tx.TransactionFilter$1.perform(
> TransactionFilter.java:73)
> at
> org.apache.cayenne.tx.TransactionFilter$1.perform(
> TransactionFilter.java:70)
> at
> org.apache.cayenne.tx.DefaultTransactionManager.performInTransaction(
> DefaultTransactionManager.java:53)
> at org.apache.cayenne.tx.TransactionFilter.onSync(
> TransactionFilter.java:70)
> at
> org.apache.cayenne.access.DataDomain$DataDomainSyncFilterChain.
> onSync(DataDomain.java:746)
> at org.apache.cayenne.access.DataDomain.onSync(DataDomain.java:585)
> at org.apache.cayenne.access.DataContext.flushToParent(
> DataContext.java:744)
> at org.apache.cayenne.access.DataContext.commitChanges(
> DataContext.java:693)
>
>
>
> --
> View this message in context: http://cayenne.195.n3.nabble.com/Erratic-
> AshwoodEntitySorter-NPE-on-Latest-Snapshot-tp4027453p4028307.html
> Sent from the Cayenne - User mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Erratic AshwoodEntitySorter NPE on Latest Snapshot

fael
Hi Michael,

Thanks for your reply here!

I did indeed come across the discussions on the Ashwood sorter and circular dependencies. When you speak of a circular object graph and taking your A -> B ... -> A example I just wanted to clarify and confirm that your example is essentially as follows;

Imagine these are the tables;
A[id (primary key), b_id]
B[id (primary key), c_id]
C[id (primary key), d_id]
D[id (primary key), e_id]
E[id (primary key), a_id]

And these the foreign keys;
A.b_id - B.id
B.c_id - C.id
C.d_id - D.id
D.e_id - E.id
E.a_id - A.id

--------------

The sort of cycle I might have is as follows;

Person[id (pk), country_id, telephone_id]
Telephone[id (pk), country_id, number]
Country[id (pk)]

Person.country_id = Country.id
Person.telephone_id = Telephone.id
Telephone.country_id = Country.id

Do you think this counts as the sort of cycle that might cause this sort of dice rolling effect?

Thanks again!
Peter

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Erratic AshwoodEntitySorter NPE on Latest Snapshot

Michael Gentry-2
PS. I wasn't intending to be confusing with the recursive relationship
comment.  I just wanted to illustrate that as far as Cayenne/Ashwood are
concerned, there is a difference between A->B->A and A->A.  The first is
circular, the second is recursive.  To quote the AshwoodEntitySorter
documentation: "Presently it works for acyclic [what I called circular, or
non-circular in this instance] database schemas with possible
multi-reflexive [what I called recursive] tables."


On Thu, Dec 8, 2016 at 11:30 AM, Michael Gentry <[hidden email]>
wrote:

> Hi Peter,
>
> I don't think that's a circular graph, unless perhaps you have more
> relationships that are omitted.  You have:
>
> Person->Country
> Person->Telephone->Country
>
> Neither of those circle back to Person.  Note: It's fine to have
> Person->Person.  Cayenne supports recursive relationships.
>
> mrg
>
>
>
> On Thu, Dec 8, 2016 at 10:14 AM, fael <[hidden email]> wrote:
>
>> Hi Michael,
>>
>> Thanks for your reply here!
>>
>> I did indeed come across the discussions on the Ashwood sorter and
>> circular
>> dependencies. When you speak of a circular object graph and taking your A
>> ->
>> B ... -> A example I just wanted to clarify and confirm that your example
>> is
>> essentially as follows;
>>
>> Imagine these are the tables;
>> A[id (primary key), b_id]
>> B[id (primary key), c_id]
>> C[id (primary key), d_id]
>> D[id (primary key), e_id]
>> E[id (primary key), a_id]
>>
>> And these the foreign keys;
>> A.b_id - B.id
>> B.c_id - C.id
>> C.d_id - D.id
>> D.e_id - E.id
>> E.a_id - A.id
>>
>> --------------
>>
>> The sort of cycle I might have is as follows;
>>
>> Person[id (pk), country_id, telephone_id]
>> Telephone[id (pk), country_id, number]
>> Country[id (pk)]
>>
>> Person.country_id = Country.id
>> Person.telephone_id = Telephone.id
>> Telephone.country_id = Country.id
>>
>> Do you think this counts as the sort of cycle that might cause this sort
>> of
>> dice rolling effect?
>>
>> Thanks again!
>> Peter
>>
>>
>>
>>
>>
>> --
>> View this message in context: http://cayenne.195.n3.nabble.c
>> om/Erratic-AshwoodEntitySorter-NPE-on-Latest-Snapshot-tp4027
>> 453p4028309.html
>> Sent from the Cayenne - User mailing list archive at Nabble.com.
>>
>
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Erratic AshwoodEntitySorter NPE on Latest Snapshot

Andrus Adamchik
Hi Peter,

Not sure if this has been mentioned in this thread already, but once you identify the entities with messed up order, you can use @SortWeight annotation and WeightedAshwoodEntitySorter. E.g.:

https://lists.apache.org/thread.html/0452cd5ca9de85f19882539710588f1b221da7627f845902ed10a7b6@1461051077@%3Cuser.cayenne.apache.org%3E

This is not a universal solution, but may help with a number of Ashwood sorter shortcomings.

Andrus


> On Dec 8, 2016, at 9:20 PM, Michael Gentry <[hidden email]> wrote:
>
> PS. I wasn't intending to be confusing with the recursive relationship
> comment.  I just wanted to illustrate that as far as Cayenne/Ashwood are
> concerned, there is a difference between A->B->A and A->A.  The first is
> circular, the second is recursive.  To quote the AshwoodEntitySorter
> documentation: "Presently it works for acyclic [what I called circular, or
> non-circular in this instance] database schemas with possible
> multi-reflexive [what I called recursive] tables."
>
>
> On Thu, Dec 8, 2016 at 11:30 AM, Michael Gentry <[hidden email]>
> wrote:
>
>> Hi Peter,
>>
>> I don't think that's a circular graph, unless perhaps you have more
>> relationships that are omitted.  You have:
>>
>> Person->Country
>> Person->Telephone->Country
>>
>> Neither of those circle back to Person.  Note: It's fine to have
>> Person->Person.  Cayenne supports recursive relationships.
>>
>> mrg
>>
>>
>>
>> On Thu, Dec 8, 2016 at 10:14 AM, fael <[hidden email]> wrote:
>>
>>> Hi Michael,
>>>
>>> Thanks for your reply here!
>>>
>>> I did indeed come across the discussions on the Ashwood sorter and
>>> circular
>>> dependencies. When you speak of a circular object graph and taking your A
>>> ->
>>> B ... -> A example I just wanted to clarify and confirm that your example
>>> is
>>> essentially as follows;
>>>
>>> Imagine these are the tables;
>>> A[id (primary key), b_id]
>>> B[id (primary key), c_id]
>>> C[id (primary key), d_id]
>>> D[id (primary key), e_id]
>>> E[id (primary key), a_id]
>>>
>>> And these the foreign keys;
>>> A.b_id - B.id
>>> B.c_id - C.id
>>> C.d_id - D.id
>>> D.e_id - E.id
>>> E.a_id - A.id
>>>
>>> --------------
>>>
>>> The sort of cycle I might have is as follows;
>>>
>>> Person[id (pk), country_id, telephone_id]
>>> Telephone[id (pk), country_id, number]
>>> Country[id (pk)]
>>>
>>> Person.country_id = Country.id
>>> Person.telephone_id = Telephone.id
>>> Telephone.country_id = Country.id
>>>
>>> Do you think this counts as the sort of cycle that might cause this sort
>>> of
>>> dice rolling effect?
>>>
>>> Thanks again!
>>> Peter
>>>
>>>
>>>
>>>
>>>
>>> --
>>> View this message in context: http://cayenne.195.n3.nabble.c
>>> om/Erratic-AshwoodEntitySorter-NPE-on-Latest-Snapshot-tp4027
>>> 453p4028309.html
>>> Sent from the Cayenne - User mailing list archive at Nabble.com.
>>>
>>
>>

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Erratic AshwoodEntitySorter NPE on Latest Snapshot

fael
Hi Andrus,

Thanks for this! I have tried this now with limited success in some of the problem cases I was experiencing but now experience a completely new exception I'm afraid!!

Stack Trace:
java.lang.NullPointerException
at org.apache.cayenne.ashwood.AshwoodEntitySorter$DbEntityComparator.compare(AshwoodEntitySorter.java:364)
at org.apache.cayenne.ashwood.AshwoodEntitySorter$DbEntityComparator.compare(AshwoodEntitySorter.java:351)
at org.apache.cayenne.lifecycle.sort.WeightedAshwoodEntitySorter$WeightedDbEntityComparator.compare(WeightedAshwoodEntitySorter.java:99)
at org.apache.cayenne.lifecycle.sort.WeightedAshwoodEntitySorter$WeightedDbEntityComparator.compare(WeightedAshwoodEntitySorter.java:91)
at java.util.TimSort.countRunAndMakeAscending(TimSort.java:355)
at java.util.TimSort.sort(TimSort.java:220)
at java.util.Arrays.sort(Arrays.java:1512)
at java.util.ArrayList.sort(ArrayList.java:1454)
at java.util.Collections.sort(Collections.java:175)
at org.apache.cayenne.ashwood.AshwoodEntitySorter.sortDbEntities(AshwoodEntitySorter.java:182)
at org.apache.cayenne.access.DataDomainInsertBucket.appendQueriesInternal(DataDomainInsertBucket.java:56)
at org.apache.cayenne.access.DataDomainSyncBucket.appendQueries(DataDomainSyncBucket.java:78)
at org.apache.cayenne.access.DataDomainFlushAction.preprocess(DataDomainFlushAction.java:189)
at org.apache.cayenne.access.DataDomainFlushAction.flush(DataDomainFlushAction.java:145)
at org.apache.cayenne.access.DataDomain.onSyncFlush(DataDomain.java:629)
at org.apache.cayenne.access.DataDomain.onSyncNoFilters(DataDomain.java:598)
at org.apache.cayenne.access.DataDomain$DataDomainSyncFilterChain.onSync(DataDomain.java:746)
at org.apache.cayenne.tx.TransactionFilter$1.perform(TransactionFilter.java:73)
at org.apache.cayenne.tx.TransactionFilter$1.perform(TransactionFilter.java:70)
at org.apache.cayenne.tx.DefaultTransactionManager.performInTransaction(DefaultTransactionManager.java:87)
at org.apache.cayenne.tx.DefaultTransactionManager.performInLocalTransaction(DefaultTransactionManager.java:59)
at org.apache.cayenne.tx.DefaultTransactionManager.performInTransaction(DefaultTransactionManager.java:52)
at org.apache.cayenne.tx.DefaultTransactionManager.performInTransaction(DefaultTransactionManager.java:40)
at org.apache.cayenne.tx.TransactionFilter.onSync(TransactionFilter.java:70)
at org.apache.cayenne.access.DataDomain$DataDomainSyncFilterChain.onSync(DataDomain.java:746)
at org.apache.cayenne.access.DataDomain.onSync(DataDomain.java:585)
at org.apache.cayenne.access.DataContext.flushToParent(DataContext.java:742)

Thanks!
Peter
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Erratic AshwoodEntitySorter NPE on Latest Snapshot

Andrus Adamchik
This looks very close to the error that you had in February:

  https://lists.apache.org/list.html?user@...:2016-2

I just committed some debug code that should help you to identify the entities involved:

  https://github.com/apache/cayenne/commit/fb4db81d2808b2baced1d0a1417ce3e8cdc0435e

So perhaps we can narrow it down to a specific mapping scenario.

Andrus

> On Dec 15, 2016, at 2:23 PM, fael <[hidden email]> wrote:
>
> Hi Andrus,
>
> Thanks for this! I have tried this now with limited success in some of the
> problem cases I was experiencing but now experience a completely new
> exception I'm afraid!!
>
> Stack Trace:
> java.lang.NullPointerException
> at
> org.apache.cayenne.ashwood.AshwoodEntitySorter$DbEntityComparator.compare(AshwoodEntitySorter.java:364)
> at
> org.apache.cayenne.ashwood.AshwoodEntitySorter$DbEntityComparator.compare(AshwoodEntitySorter.java:351)
> at
> org.apache.cayenne.lifecycle.sort.WeightedAshwoodEntitySorter$WeightedDbEntityComparator.compare(WeightedAshwoodEntitySorter.java:99)
> at
> org.apache.cayenne.lifecycle.sort.WeightedAshwoodEntitySorter$WeightedDbEntityComparator.compare(WeightedAshwoodEntitySorter.java:91)
> at java.util.TimSort.countRunAndMakeAscending(TimSort.java:355)
> at java.util.TimSort.sort(TimSort.java:220)
> at java.util.Arrays.sort(Arrays.java:1512)
> at java.util.ArrayList.sort(ArrayList.java:1454)
> at java.util.Collections.sort(Collections.java:175)
> at
> org.apache.cayenne.ashwood.AshwoodEntitySorter.sortDbEntities(AshwoodEntitySorter.java:182)
> at
> org.apache.cayenne.access.DataDomainInsertBucket.appendQueriesInternal(DataDomainInsertBucket.java:56)
> at
> org.apache.cayenne.access.DataDomainSyncBucket.appendQueries(DataDomainSyncBucket.java:78)
> at
> org.apache.cayenne.access.DataDomainFlushAction.preprocess(DataDomainFlushAction.java:189)
> at
> org.apache.cayenne.access.DataDomainFlushAction.flush(DataDomainFlushAction.java:145)
> at org.apache.cayenne.access.DataDomain.onSyncFlush(DataDomain.java:629)
> at org.apache.cayenne.access.DataDomain.onSyncNoFilters(DataDomain.java:598)
> at
> org.apache.cayenne.access.DataDomain$DataDomainSyncFilterChain.onSync(DataDomain.java:746)
> at
> org.apache.cayenne.tx.TransactionFilter$1.perform(TransactionFilter.java:73)
> at
> org.apache.cayenne.tx.TransactionFilter$1.perform(TransactionFilter.java:70)
> at
> org.apache.cayenne.tx.DefaultTransactionManager.performInTransaction(DefaultTransactionManager.java:87)
> at
> org.apache.cayenne.tx.DefaultTransactionManager.performInLocalTransaction(DefaultTransactionManager.java:59)
> at
> org.apache.cayenne.tx.DefaultTransactionManager.performInTransaction(DefaultTransactionManager.java:52)
> at
> org.apache.cayenne.tx.DefaultTransactionManager.performInTransaction(DefaultTransactionManager.java:40)
> at org.apache.cayenne.tx.TransactionFilter.onSync(TransactionFilter.java:70)
> at
> org.apache.cayenne.access.DataDomain$DataDomainSyncFilterChain.onSync(DataDomain.java:746)
> at org.apache.cayenne.access.DataDomain.onSync(DataDomain.java:585)
> at org.apache.cayenne.access.DataContext.flushToParent(DataContext.java:742)
>
> Thanks!
> Peter
>
>
>
> --
> View this message in context: http://cayenne.195.n3.nabble.com/Erratic-AshwoodEntitySorter-NPE-on-Latest-Snapshot-tp4027453p4028338.html
> Sent from the Cayenne - User mailing list archive at Nabble.com.

Loading...