-->
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: Foreign key in compiste primary key (duplicated column error
PostPosted: Fri Feb 06, 2015 11:49 am 
Newbie

Joined: Fri Feb 06, 2015 11:24 am
Posts: 1
Hello,

We are just integrating Hibernate in our web application which has been developed since today using direct queries to a relational database.
We have generated hbm.xml files in order to have all the entities and mappings implemented for accessing database via hibernate for reading and writing.

The thing is that our schema has many composite primary keys and, because of that, we have a lot of foreign keys refering to those composite ids.

Above you can see an example of database schema in which we are having many problems. There is also the hbm.xml file:
Code:
<class name="Profile" table="Profile" optimistic-lock="version">
    <id name="profileId" type "java.lang.Integer">
          <column name="profileId" />
          <generator class="assigned" />
    </id>
    <many-to-one name="location" class="Location" fetch="select" >
          <column name="locationId" length="3" not-null="true" />
    </many-to-one>
     <many-to-one name="users" class="Users" fetch="select">
          <column name="locationId" length="3" not-null="true" />
          <column name="userId" length="30" not-null="true" />
    </many-to-one>
     <many-to-one name="groupUsers" class="GroupUsers" fetch="select">
          <column name="locationId" length="3" not-null="true" />
          <column name="groupUserId" length="30" not-null="true" />
    </many-to-one>
</class>

<class name="Users" table="Users" optimistic-lock="version">
        <composite-id name="id" class="UsersId">
            <key-property name="locationId" type="string">
                <column name="locationId" length="3" />
            </key-property>
            <key-property name="userId" type="string">
                <column name="userId" length="30" />
            </key-property>
        </composite-id>

        <set name="profiles" table="Profile" inverse="true" lazy="true" fetch="select">
            <key>
                <column name="locationId" length="3" not-null="true" />
                <column name="userId" length="30" not-null="true" />
            </key>
            <one-to-many class="Profile" />
        </set>
</class>

<class name="GroupUsers" table="GroupUsers" optimistic-lock="version">
        <composite-id name="id" class="GroupUsersId">
            <key-property name="locationId" type="string">
                <column name="locationId" length="3" />
            </key-property>
            <key-property name="groupUserId" type="string">
                <column name="groupUserId" length="30" />
            </key-property>
        </composite-id>

        <set name="profiles" table="Profile" inverse="true" lazy="true" fetch="select">
            <key>
                <column name="locationId" length="3" not-null="true" />
                <column name="groupUserId" length="30" not-null="true" />
            </key>
            <one-to-many class="Profile" />
        </set>
</class>

<class name="Location" table="Location" optimistic-lock="version">
        <id name="locationId" type="string">
            <column name="locationId" length="3" />
            <generator class="assigned" />
        </id>

        <set name="profiles" table="Profile" inverse="true" lazy="true" fetch="select">
            <key>
                <column name="locationId" length="3" not-null="true" />
            </key>
            <one-to-many class="Profile" />
        </set>
</class>


When starting Tomcat I get the following error: "Profile column: locationId (should be mapped with insert="false" update="false")"
But if I try to put this two attributes in the many-to-one relation of the Profile.hbm.xml file, I can't insert a profile instance to the database (no effect):

Code:
<many-to-one name="location" class="Location" fetch="select" insert="false" update="false">
          <column name="locationId" length="3" not-null="true" />
    </many-to-one>
     <many-to-one name="users" class="Users" fetch="select"insert="false" update="false">
          <column name="locationId" length="3" not-null="true" />
          <column name="userId" length="30" not-null="true" />
    </many-to-one>
     <many-to-one name="groupUsers" class="GroupUsers" fetch="select" insert="false" update="false">
          <column name="locationId" length="3" not-null="true" />
          <column name="groupUserId" length="30" not-null="true" />
    </many-to-one>



Can anyone help me, please?
Thank you very much in advance.


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.