tags:

views:

122

answers:

1

I have a property definition table and second one that holds the actual property values:

table propdef: id, name, description 
table props: id, propdefid, userid, value

This way i can dynamically create properties for my users. When I want to update a property for a user I have to check the props table if a propdefid/userid row exists and then either use update or create on this.

Right now I am first querying the db and then deciding on what to do in my java code. Is there a way to do that in the ibatis sqlmap - without extra logic in my java code?

I am using mysql as db.

+1  A: 

before you go any farther, you need to stop and read this article: http://tonyandrews.blogspot.com/2004/10/otlt-and-eav-two-big-design-mistakes.html

if you still decide that EAV is the way to go, there is still hope. i can't advise at the ibatis/java level, but i can tell you to look at INSERT ... ON DUPLICATE KEY UPDATE. this change your two statements in to one.

longneck
I normally dislike EAVs - but in this case cant be avoided. I will go for the "insert on duplicate key update" thing - didnt know about that - thanks!
Niko