On 22/04/2009, at 2:58 AM, Robert Zeigler wrote:

Hm.... have you considered using runtime relationships? (NOTE: I've never played with this, myself, so take the next bit with a grain of salt. :) In theory, it's entirely possible with cayenne to have a single generic data object and then modify the mapping information at runtime as necessary.
So... I /think/ you could do something along the following lines:

Register a global lifecycle listener that listens to whatever events you need: in your case, I would say you probably need post-load and pre-persist? And then you can add the relationship information that you need or that cayenne needs? Then the info is there for cayenne to work with. And then you can use the generic writeProperty/writeRelationship methods to access the information in those properties as needed. This might be a long shot...dunno... like I said... I haven't tried it. But if I wanted to have relationships without having relationships, this is likely the approach I would start looking at.

I'd be interested in hearing what others have to say... feasible given the current cayenne stack?

Unless you have real database relations you aren't going to get any benefit of being able to use Cayenne to follow relations. At some point in Cayenne it will try to follow joins by using SQL JOINs. Unless Andrus has a trick for making this work, I suspect your approach is clever but ultimately will run into difficulties.

The problem is that the original poster is trying to use Cayenne like he uses pure SQL and he hasn't demonstrated how he would even achieve what he wants with pure SQL (hint: LAST_INSERT_ID() is the mysql specific way of getting the last id. His other approaches just don't work. But even LAST_INSERT_ID() would probably create race conditions with multiple concurrent users.)

There is however a solution to relationships or attributes which need to be added to 75% of the tables in the database: inheritance. In this case vertical inheritance is the appropriate choice. We are just now testing the excellent work Andrus has done in this area and we have all the basic parts of inheritance working in ROP.


Ari Maniatis


-------------------------->
ish
http://www.ish.com.au
Level 1, 30 Wilson Street Newtown 2042 Australia
phone +61 2 9550 5001   fax +61 2 9550 4001
GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A


Reply via email to