-->
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.  [ 3 posts ] 
Author Message
 Post subject: syntax for creating unique index in mapping file
PostPosted: Wed Mar 23, 2005 11:55 am 
Newbie

Joined: Wed Feb 23, 2005 2:08 pm
Posts: 17
Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp

I would like to create a unique index on columns(LOGIN_NAME/PASSWORD). what is the syntax to have this generated from the mapping. thanks in advance

Scott

Hibernate version:2.18

Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class name="com.ipdsserver.persistence.Contact" table="CONTACT">
<meta attribute="class-description">
Represents a contact.
</meta>

<id name="id" type="long" column="CONTACT_ID">
<meta attribute="scope-set">protected</meta>
<meta attribute="field-description">Unique identity - automatically generated</meta>
<generator class="native" />
</id>

<property name="firstName" type="string">
<meta attribute="use-in-tostring">true</meta>
<meta attribute="field-description">The contact's first name</meta>
<column name="FNAME" length="40" not-null="true" />
</property>

<property name="middleName" type="string">
<meta attribute="field-description">The contact's middle name</meta>
<column name="MNAME" length="40" />
</property>

<property name="lastName" type="string">
<meta attribute="use-in-tostring">true</meta>
<meta attribute="field-description">The contact's last name</meta>
<column name="LNAME" length="40" not-null="true" />
</property>

<property name="phone" type="string">
<meta attribute="field-description">The contact's phone number</meta>
<column name="PHONE" length="40" />
</property>

<property name="email" type="string">
<meta attribute="use-in-tostring">true</meta>
<meta attribute="field-description">The contact's email address</meta>
<column name="EMAIL_ADDRESS" length="60" not-null="true" />
</property>

<many-to-one name="type" column="TYPE_ID"
class="com.ipdsserver.persistence.ContactType"
cascade="save-update"
not-null="true" />

<many-to-one name="role" column="ROLE_ID"
class="com.ipdsserver.persistence.Role"
cascade="save-update"
not-null="true" />

<many-to-one name="mainAddress" column="MAIN_ADDRESS_ID"
class="com.ipdsserver.persistence.Address"
cascade="save-update"
not-null="true" />


<set name="addresses" table="ADDDRESS" cascade="all">
<key column="CONTACT_ID" />
<one-to-many class="com.ipdsserver.persistence.Address" />
</set>


<property name="loginName" type="string">
<meta attribute="use-in-tostring">true</meta>
<meta attribute="field-description">The login name for the contact</meta>
<column name="LOGIN_NAME" length="25" not-null="true"/>
</property>

<property name="password" type="string">
<meta attribute="use-in-tostring">true</meta>
<meta attribute="field-description">The password for the contact</meta>
<column name="PASSWORD" length="30" not-null="true"/>
</property>
<property name="lastSaved" type="timestamp">
<meta attribute="field-description">The contact's last saved date</meta>
<column name="LAST_SAVED" not-null="true" />
</property>

</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject: my bad, I would like to create a unique constraint
PostPosted: Thu Mar 24, 2005 9:28 am 
Newbie

Joined: Wed Feb 23, 2005 2:08 pm
Posts: 17
I would like to create a constraint so the combination of LOGIN_NAME/PASSWORD is unique.

If anyone could just say if this can be done through a mapping file, I would appreciate it. I have not seen this documented but perhaps I overlooked it. Obviously I can do this using sql but would prefer to have it in the generated ddl by hibernate.

Scott


Top
 Profile  
 
 Post subject: here's how
PostPosted: Tue Mar 29, 2005 4:59 pm 
Newbie

Joined: Wed Feb 23, 2005 2:08 pm
Posts: 17
<property name="loginName" type="string">
<meta attribute="use-in-tostring">true</meta>
<meta attribute="field-description">The login name for the contact</meta>
<column name="LOGIN_NAME" length="25" not-null="true" unique-key="CON_USR_PASS"/>
</property>

<property name="password" type="string">
<meta attribute="use-in-tostring">true</meta>
<meta attribute="field-description">The password for the contact</meta>
<column name="PASSWORD" length="30" not-null="true" unique-key="CON_USR_PASS"/>
</property>


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