-->
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: Mapping for 2 default ACEGI tables
PostPosted: Sun Mar 23, 2008 10:55 am 
Regular
Regular

Joined: Mon Mar 10, 2008 6:40 pm
Posts: 114
How should I map the 2 following default ACEGI tables? Apparently I need a primary key for the authorities table, but am discouraged in the documentation from using composite ids for anything other than legacy code.

So what's the best practice for this very common situation? Is it appropriate to use a composite id for all fields in the authorities table even though this isn't legacy code? I think it's fairly normal for 1 table have a one-to-many mapping with fields from another table where that other table (authorities in this case) has no need for an ID. Should I add an ID to the authorities table?

CREATE TABLE users (
username VARCHAR(50) NOT NULL PRIMARY KEY,
password VARCHAR(50) NOT NULL,
enabled BIT NOT NULL
);

CREATE TABLE authorities (
username VARCHAR(50) NOT NULL,
authority VARCHAR(50) NOT NULL
);


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 23, 2008 11:08 am 
Regular
Regular

Joined: Mon Mar 10, 2008 6:40 pm
Posts: 114
I just tried to do the composite-id method and I get an error. Apparently I can't use one of the fields specified in the composite-id for anything other than the composite-id. So this didn't work:
Code:
    <class name="com.company.Authority" table="Authorities">
        <composite-id>
            <key-property name="username" column="Username"/>
            <key-property name="authority" column="Authority"/>
        </composite-id>
        <!--<property name="authority" column="Authority" length="255"/>-->
        <many-to-one name="user" class="com.company.User" column="Username"/>
    </class>

I had tried commenting out the authority property, but the many-to-one relationship uses the same column as in the first key-property. If I take that out, then I don't get my many-to-one relationship.


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.