-->
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.  [ 8 posts ] 
Author Message
 Post subject: composite unique property
PostPosted: Mon Jul 05, 2004 3:34 pm 
Newbie

Joined: Mon Jul 05, 2004 3:16 pm
Posts: 4
Hello All,

I have to design a mapping where two properties combined together are unique. I cannot use a composite-id for this as the primary key is self generated.

I have noticed a tag called composite-element, but it says that I have to use components for it. I am not sure if I want to use that.

Basically from the main frame system, the B2B system gets a XML file pertaining to a order. Now the order may consist of multiple items and each item is associated with a line number. Now in the mapping for a item, I want to describe that item together with the order id form a composite unique property.

What should/can I use to acheive the above functionality? This might sound something primitive, but please note that I am a beginner and am not an expert in DBAdministration.

Thanks,

Alpha.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 06, 2004 10:53 am 
Newbie

Joined: Mon Jul 05, 2004 3:16 pm
Posts: 4
Any thoughts/suggestions would be highly appreciated.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 06, 2004 12:00 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
show what you've already done in your mapping and show you DB schema.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 06, 2004 2:55 pm 
Newbie

Joined: Mon Jul 05, 2004 3:16 pm
Posts: 4
Hello emmanuel,

Thanks for replying. Here is a snippet of my mapping file.

<hibernate-mapping>
<class name="com.islandpacific.hibernate.LineItem"
table="line_item" dynamic-update="true">

<id name="id" type="long" column="id" unsaved-value="0" >
<generator class="vm"/>
</id>

<property name="lineNumber" type="int"
column="line_num" length="3" />

<many-to-one class="com.islandpacific.hibernate.PODetails"
name="poID" column="po_id" />

.................
</class>

So I want to describe that the combination of lineNumber and poID is unique in the table.

There is a slight change in the table now as poID is the primary key of another table po_details. The mapping for that table is as follows ...

<hibernate-mapping>
<class name="com.islandpacific.hibernate.PODetails"
table="po_details" dynamic-update="true">

<id name="orderID" type="int" column="order_id" unsaved-value="0" >
<generator class="vm"/>
</id>

<property name="poNumber" column="po_number"
type="string" length="10" not-null="true" unique="true"/>

.....
</class>

The table for po_details looks like below

PK : order_id
po_number
revision_number
......

The table for line_item looks like below
PK: id
line_num
FK: order_id
class
size
color
.....

Hoping to hear from you...

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 07, 2004 10:42 am 
Newbie

Joined: Mon Jul 05, 2004 3:16 pm
Posts: 4
Is this a bigger problem than it looks like? I thought this must be something primitive. I do not have any hibernate resources with me now and am in the process of getting the books. All I refer to is the Hibernate reference document. I have gone through that a couple of times and still do not see anything other than the composite-element suitable for my needs.

Any suggestions/pointers would be heartily welcomed.

Thanks,

Rave.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 12, 2004 12:12 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
There is no good solution I guess :
- check this uniqueness at the Java level in a process layer
- add a unique constraint in you DB

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 27, 2004 1:11 pm 
Newbie

Joined: Fri Aug 27, 2004 1:06 pm
Posts: 2
Hi,

I am looking for a similar solution.

Have a table, in which the combination of the foreign key and one column have to be unique.

Is there any Hibernate solution for this?

My workaround now is to change the database schema after hibernate creates the tables.

But I think it's no good solution to change the database schema by hand, because the hibernate mapping files should be the master template for the database.

Any solution in Hibernate mapping files available?

Thanks in advance,

Pieper


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 31, 2004 8:49 am 
Newbie

Joined: Fri Aug 27, 2004 1:06 pm
Posts: 2
Hi,

is there no possibilty to do this in Hibernate mapping file?

Regards,
Pieper


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