Composite PK Support planned?

84 views
Skip to first unread message

J Zimmermann

unread,
Apr 27, 2015, 11:42:19 AM4/27/15
to activejd...@googlegroups.com
Hey ActiveJDBC community,
I got a composite PK table schema without primary key 'id' column and tried to use ActiveJDBC without success.
I couldn't find any workaround for update my model entries without changing the table structure.
Ok, I found the current position for Composite PK support here (http://javalite.io/surrogate_primary_keys).

But anyway, I started a fork and pushed it into (https://github.com/comtel2000/activejdbc/tree/composite-pk)
Is there a chance to get composite PK support into the main release in the near future?

Best regards,
Joerg

Igor Polevoy

unread,
Apr 27, 2015, 2:52:14 PM4/27/15
to activejd...@googlegroups.com
Joerg, we will look at your fork but there is a lot  of stuff hinges on having the ID column (even if not a PK). 
Currently we have no plans for support of composite PKs, 

thanks

Igor Polevoy

unread,
Apr 27, 2015, 2:53:39 PM4/27/15
to activejd...@googlegroups.com
By the way, does your fork pass all tests at least on MySQL? 

J Zimmermann

unread,
Apr 27, 2015, 9:03:13 PM4/27/15
to activejd...@googlegroups.com
Yes, all tests passed with H2, MySQL and MSSQL

Igor Polevoy

unread,
Apr 29, 2015, 4:31:51 PM4/29/15
to activejd...@googlegroups.com
Hi, Bart. I will take a look at your fork in the next few days, will let you know here. 

J Zimmermann

unread,
Apr 29, 2015, 6:54:58 PM4/29/15
to activejd...@googlegroups.com
Great, Igor. There is a test case available here:
https://github.com/comtel2000/activejdbc/blob/composite-pk/activejdbc/src/test/java/org/javalite/activejdbc/CompositePkTest.java

package org.javalite.activejdbc.test_models;

import org.javalite.activejdbc.Model;
import org.javalite.activejdbc.annotations.IdCompositeKeys;

@IdCompositeKeys({ "first_name", "last_name", "email" })
public class Composites extends Model {
static {
validatePresenceOf("first_name", "last_name", "email").message(
"one or more composite PK's missing!!!");
}
}

Igor Polevoy

unread,
Apr 29, 2015, 10:49:18 PM4/29/15
to activejd...@googlegroups.com
thanks, I will certainly look at the tests as well

J Zimmermann

unread,
Jun 7, 2015, 7:39:02 PM6/7/15
to activejd...@googlegroups.com
Igor,
could you already cast a glance into it?

Igor Polevoy

unread,
Jun 7, 2015, 10:06:43 PM6/7/15
to activejd...@googlegroups.com
Hi, J. 

Sorry for delay (swamped with work) - I will look into it tomorrow!

thanks
igor

Igor Polevoy

unread,
Jun 7, 2015, 10:19:36 PM6/7/15
to activejd...@googlegroups.com
Joerg, just did a review of your fork. 

I thought I had to take a long time for review, and so I delayed it. However, it took less than 10 minutes. 
In any case, here is my feedback: 

What you have probably works for simple cases. For instance, you can save an search a single model based on composite key. 
However, the framework provides the most power by building relationships (one to many, many to many and polymorphic )
All these relationships are dependent on surrogate PK, but your implementation does not include any of them. 
In other words, how can I have a one to many relationship, if the child table does not have an ID, but provides complex composite key?
So, in a sense you implementation works  and can be adopted into the framework with understanding that it is limited and does not support relationships. 

Adding real relationships for composite keys will take a lot more work. 

Is this making sense ?

Thanks
igor 

J Zimmermann

unread,
Jun 8, 2015, 6:14:48 PM6/8/15
to activejd...@googlegroups.com
Thanks Igor, I fully agree with you. It doesn't provide any foreign key or caching support for now.
I really like the light weight ActiveJdbc concept and maybe some features are to heavy or rarely used.
But anyway, I never used a composite foreign keys in one of my data model and a limited function might
be an option for mixed id/comp.key models.
Best regards, Joerg

Igor Polevoy

unread,
Jun 9, 2015, 7:53:22 PM6/9/15
to activejd...@googlegroups.com
Joerg, if you are OK with this, I can accept a pull request once you send it. 

thanks
Igor 
Reply all
Reply to author
Forward
0 new messages