-->
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.  [ 2 posts ] 
Author Message
 Post subject: Problem with duplicates
PostPosted: Thu Mar 19, 2009 1:41 pm 
Newbie

Joined: Thu Mar 13, 2008 7:43 am
Posts: 1
Location: Lisbon
Hi, I've mapped a table this way:

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="pt.global.data.hibernate.models" default-access="field">
    <class name="GraEvent" table="GRA_EVENT">
      <id name="id" column="ID_SEQ">
            <generator class="increment"/>
        </id>
        <natural-id mutable="false">
         <property name="idCalendar" update="false">
            <column name="ID_CALENDAR"
               unique="true"
               length="30"
               not-null="true" />
         </property>
      </natural-id>
        <property column="TITLE" not-null="true" name="title" length="100" />
        <property column="TYPE" not-null="true" name="type" length="5" />
        <property column="STATUS" not-null="true" name="status" length="5" />
    </class>
   
</hibernate-mapping>


But it is allowing me to insert records with the same ID_CALENDAR. Shouldn't the framework throw an exception when I tried to insert a duplicate?

Kind regards,

Carlos Ferreira

_________________
Life is what happens to you while you're busy making other plans.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 19, 2009 2:56 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
It is really not possible to do this inside the framework considering that multiple transactions may be going on at once. Instead, the check is assumed to be made by the database. If you use the schema generation tool to create the database, Hibernate will also create the proper constraints for checking the uniqueness. In your case, you'll need a unique constraint on the ID_CALENDAR column.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.