-->
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: Can I re-use one column from comp-id into a unique-index ?
PostPosted: Sun Oct 05, 2008 3:11 pm 
Newbie

Joined: Mon Feb 25, 2008 11:49 pm
Posts: 6
Hibernate version:
Hibernate-Version: 3.1.3

Mapping documents:

+ This is the mapping for a USER table

Code:
    <composite-id name="comp_id" class="UserPK">
        <key-property
            name="quarter"
            column="QUARTER"
            type="java.lang.String"
            length="7"
        />
        <key-property
            name="userId"
            column="USER_ID"
            type="java.lang.String"
            length="12"
        />
    </composite-id>
    ....
    <property
        name="login"
        type="java.lang.String"
        column="USER_LOGIN"
        not-null="true"
        length="80"
    />


My question is :

Can I create a mapping to generate a unique constraint with the QUARTER and USER_LOGIN fields ?

So that the table DDL would look like :
Code:
create table USER (QUARTER varchar(7) not null, USER_ID varchar(12) not null, USER_LOGIN varchar(80) not null, primary key (QUARTER, USER_ID), unique (QUARTER, USER_LOGIN))


I tried using unique-key and natural-index but I got an error saying that the QUARTER column was duplicate.

Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 06, 2008 4:10 pm 
Newbie

Joined: Mon Feb 25, 2008 11:49 pm
Posts: 6
I found a partial solution to this problem, where is what I did so far :

Added a many-to-one association pointing to the same table :

Code:
    <many-to-one
        name="ak1UserLogin"
        class="UserHB"
        insert="false"
        update="false"
        unique-key="login"
    >
        <column name="QUARTER" />
        <column name="USER_LOGIN" />
    </many-to-one>


This mapping generates the following DDL :
Code:
create table USER (QUARTER varchar(7) not null, USER_ID varchar(12) not null, USER_LOGIN varchar(80) not null, primary key (QUARTER, USER_ID), unique (QUARTER, USER_LOGIN))


So far so good, but the catch is that now it's also generating this alter table :
Code:
alter table USER add constraint FKEF82875CB55E62BC foreign key (QUARTER, USER_LOGIN) references USER


So it's creating a constraint pointing to QUARTER/USER_ID with QUARTER/USER_LOGIN which just locks the table completely :)

Anyway, it's a progress.

Anyone have any other idea ?


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.