-->
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.  [ 1 post ] 
Author Message
 Post subject: One-to-Many Association with Index As Primary Key
PostPosted: Mon Apr 23, 2007 5:40 pm 
Newbie

Joined: Fri Sep 09, 2005 4:21 am
Posts: 5
Hello everybody,

My problem is about one-to-many associations (as list) and an index attribute (see below), i searched throughout the forums, documentation of hibernate, and google but i can not find the answer. If this question is a duplicate, i am sorry for that.

I have two tables as :

USER
==========
USER_ID______________PK
USER_NAME


USER_STATUS
==============
USER_ID______________PK (FK to USER Table)
USER_STATUS_INDEX____PK (an index)
USER_LEVEL_CODE
UPDATE_DATE

Now this situation is like the example given in Chapter : 23.3.
Customer/Order/Product. But in that example, there are no java classes, only UML diagram is given.

So my mapping file is like that : (By looking to that example)

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
    <class name="net.domain.User" table="USER" schema="public">
        <id name="user_id" type="int">
            <column name="USER_ID" />
            <generator class="assigned" />
        </id>
        <property name="user_name" type="string">
            <column name="USER_NAME" not-null="true" />
        </property>

        <list name="user_status" table="USER_STATUS">
            <key column="USER_ID"/>
            <list-index column="USER_STATUS_INDEX"/>
            <composite-element class="net.domain.UserStatus">
                <property name="USER_LEVEL_CODE"/>
                <property name="UPDATE_DATE"/>
            </composite-element>
        </list>

    </class>
</hibernate-mapping>


Now my questions :

1) Is that mapping file (list section) correct? Should there be another mapping file?

2) How should be the java files? Should there be 2 java files (User, UserStatus)? Should there be a composite-id class for UserStatus or should the primary keys are defined just like attributes?

3) If hibernate will deal with the index attribute, how should be the setter and getter of that index attribute?

Hibernate version: hibernate-3.2.3.ga

Hibernate Tools version: HibernateTools-3.2.0.beta9a

Name and version of the database you are using: postgresql-8.2.3-1

Thank you.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.