-->
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 to inherited property
PostPosted: Mon Apr 14, 2008 9:18 am 
Newbie

Joined: Mon Apr 14, 2008 9:04 am
Posts: 1
Hibernate version: 3.2.1.GA

Name and version of the database you are using: MySQL 5.0.24

I have a super-class A that defines a 'name' property that is inherited by 2 sub-classes: GlobalA and LocalA. I would like for GlobalA to define this column as unique, but I can't seem to find the right way to do it.

First, I tried overriding the getResourceName() method in GlobalA, copying the annotations from the parent, and adding an '@Column(unique=true)', but I get an error during schema generation indicating that GlobalA has defined a duplicate property 'name'.

Next, I tried defining the unique constraint via the @Table annotation in GlobalA:
uniqueConstraints = { @UniqueConstraint(columnNames = { "resourceName" }) }
This results a NPE during schema generation (I can provide stack trace, if desired).

I'm not very familiar with @AttributeOverride. Is this the way to go?
For what it's worth, GlobalA is not intended to be a concrete class, so if I could use a property-specific annotation (@Column preferred over @Table), then that would definitely be preferred to duplicating the unique constraint in each concrete sub-class, but at this point I'll be happy with just about anything short of manually defining this via a SQL script.

Any help would be greatly appreciated.
-Trey


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.