-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: adding unique constraint at runtime?
PostPosted: Wed Aug 25, 2010 5:29 pm 
Newbie

Joined: Wed Mar 17, 2010 2:07 pm
Posts: 3
Hi all

I'm trying to inject some unique constraints at runtime. I've looked around and I'm lost.... any help is appreciated.

I have the following setup:
hibernate entity manager + annotations 3.5.4-Final

the model looks like
Code:
@Entity(name="User")
public class UserDBImpl {
    ....
    @Column(name="ATTRIBUTES", nullable=false)
    @ElementCollection
    @JoinTable(name="UserAttributes", joinColumns=@JoinColumn(name="username"))
    @MapKeyColumn(name="attrkey")
    private Map<String, String> attrs = new HashMap<String, String>();
    ...


so the UserAttributes table would look like:
username___________attrkey_________attrvalue
user1 attr1 foo
user2 attr1 bar

The goal is to add constraints such as "attrvalue should be unique if attrkey is 'attr1'" at runtime. By runtime, I mean any time before first database operation is requested.

I thought about custom validator but in all the examples the validator does not have access to other fields in the table. (same problem with @PostUpdate. can anyone give an example?)

I thought about ALTER TABLE, but it's a native query and I want to avoid it.

I was looking at EJB3Configuration class, hoping to make some calls to add unique constraint before an entity manager is built but I'm even more confused after looking at that class.

Any help is appreciated

thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.