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: how to use unique-key
PostPosted: Sat May 29, 2004 12:45 am 
Newbie

Joined: Sat May 29, 2004 12:29 am
Posts: 3
hi i am trying group columns together in a table so they have unique value

Mysql ddl looks like this

CREATE TABLE table1(
id bigint(20) NOT NULL auto_increment,
col1 bigint(20) NOT NULL,
col2 bigint(20) NOT NULL,
col3 bigint(20) NOT NULL,
col4 bigint(20) NOT NULL,
UNIQUE KEY (col2,col3,col4),
PRIMARY KEY(id)
) TYPE=MyISAM;

these r the ways i found in the HBRD
1) "A unique-key attribute can be used to group columns in a single unit key constraint " -- 15.1.1 Hibernate Reference Documentation 2.1.3 ( this is what i think i should use )

2) 5.1.5 Composit-id

using composit-id would make it more complex than it should be.
I think its possible to use unique-key to achive this. But there is just not enough about it in the HBRD. Only one line :( (1)

could some one please help me figure out how i could use unique-key to do this. just a simple hbm.xml for the above mentioned table would do.

Thanx a lot.


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 29, 2004 6:23 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
add unique-key="something" to all properties which have to be unique in combination.


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 29, 2004 8:17 am 
Newbie

Joined: Sat May 29, 2004 12:29 am
Posts: 3
unique-key is not a valid attribute of property
gave it a try any way, didn't work
thanx a lot for trying once u get to know it please dont forget to tell me


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 29, 2004 8:33 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Oh please show some initiative man! We are not here to hold your hand.

The unique-key attribute applies to column mappings, It is trivial to write:
Code:
<property name="foo">
    <column name="FOO" unique-key="FOOBARUK"/>
</property>

<property name="bar">
    <column name="BAR" unique-key="FOOBARUK"/>
</property>

This solution could easily have been found by searching the forum.


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 29, 2004 9:36 am 
Newbie

Joined: Sat May 29, 2004 12:29 am
Posts: 3
thanx a lot Gavin. should have figured it out just by staring at the dtd a bit longer. knock knock.

this is not what we want
<property name="foo">
<column name="FOO" unique-key="FOOBARUK"/>
</property>

<property name="bar">
<column name="BAR" unique-key="FOOBARUK"/>
</property>

create table EVENTS (uid BIGINT not null, foo VARCHAR(255), BAR VARCHAR(255), primary key (uid), unique (title, location))

mysql will complain how big the key is

what we want is this
<property name="foo">
<column name="FOO" length="50" unique-key="FOOBARUK"/>
</property>

<property name="bar">
<column name="BAR" length="50" unique-key="FOOBARUK"/>
</property>

create table EVENTS (uid BIGINT not null, foo VARCHAR(50), bar VARCHAR(50), primary key (uid), unique (title, location))


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.