-->
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.  [ 5 posts ] 
Author Message
 Post subject: Hibernate unique constraint over two column
PostPosted: Sun Jun 19, 2005 5:44 am 
Newbie

Joined: Sun Jun 19, 2005 4:13 am
Posts: 2
Location: milano
Hibernate version:2.0

Name and version of the database you are using:mysql

Hi ,

I want to mapping a group of 2 columns (nome,areaadmin) as unique constraint but I don' t like a composite key, my primary key is simple id type int.
One of two columns is also a foreign key(areaadmin)

here the code without this change.........
(I have got 1 columns as attribute 'unique' )
**********************+

<class name="com.mainsoft.pojo.CompetenzeAdmin"
table="COMPETENZEADMIN">

<id name="id" type="int"
column="COMPETENZEADMIN_ID">
<meta attribute="scope-set">protected</meta>

<generator class="native"/>
</id>
<property name="nome" type="string"
not-null="true" unique="true"/>

<set name="conoscenze" cascade="all"
inverse="true" lazy="true">
<key column="competenzeadmin_id"/>
<one-to-many
class="com.mainsoft.pojo.ConoscenzeAdmin"/>
</set>

<many-to-one name="areaadmin"
class="com.mainsoft.pojo.AreaAdmin"
column="areaadmin_id"/>
</class>
********************

help me!
Thanks,
Marcello.

_________________
Marcello Gonzato


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 19, 2005 11:57 pm 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
HI

I have the same problem but with Four Colomn.

A Sample will be very much appreciated

Thanks for Team

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 20, 2005 12:16 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
unique-key="indexName"


Or <natural-id>


Top
 Profile  
 
 Post subject: <natural-id> not working
PostPosted: Fri Aug 11, 2006 7:12 pm 
Newbie

Joined: Tue Nov 15, 2005 8:27 pm
Posts: 19
Location: Columbia, MO USA
I have the same problem with Hibernate 3.1.3. I am using <id></id> to identify the surrogate key.

I can use unique-key="indexName" and not-null="true" to identify the properties that make up the natural key and everything works fine.

However, when I try to bracket the natural key properties inside <natural-id> </natural-id>, I get an exception:

Code:
Caused by: org.xml.sax.SAXParseException: The content of element type "class" must match "(meta*,subselect?,cache?,synchronize*,comment?,tuplizer*,(id|composite-id),discriminator?,natural-id?,(version|timestamp)?,(property|many-to-one|one-to-one|component|dynamic-component|properties|any|map|set|list|bag|idbag|array|primitive-array)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*,resultset*,(query|sql-query)*)".
   at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
   at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
   at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
   at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
   at org.apache.xerces.impl.dtd.XMLDTDValidator.handleEndElement(Unknown Source)
   at org.apache.xerces.impl.dtd.XMLDTDValidator.endElement(Unknown Source)
   at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source)
   at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
   at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
   at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
   at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
   at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
   at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
   at org.dom4j.io.SAXReader.read(SAXReader.java:465)
   at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:422)
   ... 25 more

Any ideas?

Bruce


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 13, 2006 4:51 pm 
Newbie

Joined: Tue Nov 15, 2005 8:27 pm
Posts: 19
Location: Columbia, MO USA
I found the problemon my own. The order of the tags is important. It you have to specify the id, then the natural-id, then the version. I had the id, the version, then the natural-id.

Bruce


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