Re: Compound PK generation
Thomas Ganter <[email protected]> Fri, 10 Dec 2004 22:04:01 +0100
| Newsgroups | gmane.comp.web.webobjects.eof |
|---|---|
| Message-ID | <[email protected]> |
Hi Anders,
I was facing a similar problem a while ago and created my own Delegate =20=
to create compound primary keys.
It will not work under all circumstances, but serves my purposes which =20=
is to come up with a new component for a compound key if all others can =20=
be somehow determined. This is in production for more than one year =20
now.
In my situation, I faced problems like this one:
Imagine two tables, named A and B.
A has a PK keyA (char 3).
B has a compound PK keyA (char 3) and keyB (number).
C has a compound PK keyA (char 3), keyB (number) and keyC (char 1).
There is a 1:n relationship between A and B, and one 1:m between B and =20=
C where m<=3D26 (The application is abount financials, and the =
assumption =20
is quite reasonoable).
Now, wth the above delegate I can do (pseudo-code)
a <- new A
a.setKeyA( ABC )
b1 <- new B
b1. setToARelationship( a )
b2 <- new B
a.addToToBRelationship( b2 )
saveChanges()
c1 <- new C
b1.addToToCRelationship( c1 )
c2 <- new C
c2.setToBRelationship( b1 )
saveChanges()
The objects then have the PKs
a: ABC
b1: ABC, 1
b2: ABC, 2
c1: ABC, 1, A
c2: ABC, 1, B
If that is what you want and you dare to use it, please see here:
http://www.familie-ganter.de/cvsweb/_cvsweb.cgi/WebObjects/=20
PrometheusDatabase/src/kroisos/eo/helper/DatabaseDelegate.java?=20
rev=3D1.2&content-type=3Dtext/x-cvsweb-markup
I then do
=A0 =A0public Application( =A0) {
=A0 =A0 =A0
=A0 =A0 =A0 =A0super( =A0);
=A0 =A0 =A0 =A0// com.webobjects.jdbcadaptor.MysqlPlugIn.installPatch( =
=A0);
=A0 =A0 =A0 =A0kroisos.eo.helper.DatabaseDelegate.installDelegate( =A0);=
=09
...
I seem to remember that I updated the Delegate not too many month ago, =20=
removing the in-memory caching and introducing database-caching to =20
enable multiple instances, however I am since stuck in the CVS -> =20
subversion migration (yeah) and have the code somewhere at home, where =20=
I currently am not.
Greetings,
- Thomas
Am 10.12.2004 um 10:26 schrieb Anders Peterson:
> Depends on your definition of automatically/manually.
>
> It worked fine as long as the to-many relationships that should =20
> propagate the pk-components were class attributes. This, however, was =20=
> not acceptable to me. (I have changed my design.)
>
> With many-to-many relationships it is also done "automatically".
>
> /Anders
>
> On 2004-12-09, at 19.28, Ricardo Strausz wrote:
>
>> Compound keys cannot be assigned automatically by EOF. You have to =20=
>> assign them by hand.
>>
>> see the "saving objects" chapter of the "enterprise objects" book... =20=
>> it should be installed somewhere in your hd.
>>
>> Dino
>>
>> On Dec 9, 2004, at 1:06 PM, Anders Peterson wrote:
>>
>>> Hi,
>>>
>>> I have some entities with compound primary keys. The pk components =20=
>>> are all foreign keys.
>>>
>>> I can't get EOF to generate primary keys for new instances unless I =20=
>>> set the corresponding to-many relationships (leading to the =20
>>> troublesome entity) to be class attributes.
>>>
>>> This is going to give me a performance problem. Eventually there =20
>>> will be lots of instances =96 huge to-many arrays.
>>>
>>> I=92m hoping I=92ve missed something. Is the only way to get rid of =
the =20
>>> to-many class attributes to have dedicated primary key columns in =20=
>>> =93all=94 entities?
>>>
>>> /Anders
>>>
>>> _______________________________________________
>>> EOF mailing list
>>> [email protected]
>>> http://www.omnigroup.com/mailman/listinfo/eof
>>
>
> _______________________________________________
> EOF mailing list
> [email protected]
> http://www.omnigroup.com/mailman/listinfo/eof