-->
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.  [ 4 posts ] 
Author Message
 Post subject: Mapping when using constraint on key
PostPosted: Wed Oct 19, 2005 11:46 am 
If I have a table like so:

item item_name item_value

and I put a unique constraint on the item,

How do I tell my mapping abiout it? Most examples I have used, have had a surrogate key, like the below example. I would like the framework to not insrt when it sees another item with the same name (possibly case insensitive?).

Thanks,



Here is a mapping I tweaked, but I do not know how to handle the attributes for the item.

<hibernate-mapping>
<class name="com....Item" table="item" >
<item name="item" column="item" type="java.lang.String" unsaved-value="0">
<generator class="identity"/>???
</id>

<property name="itemname" column="item_name" type="java.lang.String" />
<property name="itemvalue" column="item_value" type="java.lang.String" />
</class>
</hibernate-mapping>


Top
  
 
 Post subject:
PostPosted: Wed Oct 19, 2005 11:55 am 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
Code:
unique="true"

tag for those columns.

I'd rather implement this on the db side and just catch the exception, but this is how its done in mappings.

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject: Followup to unique database insert
PostPosted: Wed Oct 19, 2005 12:07 pm 
In the database, i have marked the item as unique.

So now in my mapping, do I need to put in a id? Or just use a property name for this?

Thanks,
Scott


Top
  
 
 Post subject:
PostPosted: Wed Oct 19, 2005 1:01 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
oh yeah. If item is the primary key, designate it as the id in the mapping file. That will dictate to hibernate that it is the primary key and must be unique.

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


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

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.