-->
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.  [ 4 posts ] 
Author Message
 Post subject: net.sf.hibernate.MappingException: Repeated column in mappin
PostPosted: Tue Apr 27, 2004 1:29 am 
Newbie

Joined: Tue Apr 27, 2004 12:25 am
Posts: 1
Iam Getting following exception
net.sf.hibernate.MappingException: Repeated column in mapping for collection: com.liferay.portal.ejb.UserHBM.groups column: portalId

Mine Is Hibernate Version 2,Oracle 9i
One Part of code is below

session = HibernateUtil.openSession();

StringBuffer query = new StringBuffer();
query.append("SELECT COUNT(*) FROM ");
query.append(com.liferay.portal.ejb.UserHBM.class.getName());
query.append(" userHBM ");
query.append("JOIN userHBM.groups AS groupHBM ");
query.append("WHERE userHBM.userId = ? ").append(" AND ");
query.append("userHBM.portalId = ? ");
String pk1 = userPK.userId;
String pk2 = userPK.portalId;
Object[] values = { pk1, pk2 };
Type[] types = { Hibernate.STRING, Hibernate.STRING };
return ((Integer)session.iterate(query.toString(), values, types)
.next()).intValue();

HibernateUtil.closeSession(session);


Below is the table and mapping structure<class name="com.liferay.portal.ejb.UserHBM" table="TCPS_User_">
<composite-id name="primaryKey" class="com.liferay.portal.ejb.UserPK">
<key-property name="userId"/>
<key-property name="portalId"/>
</composite-id>
<property name="emailAddress"/>
<property name="languageId"/>
<property name="timeZoneId"/>
<property name="skinId"/>
<property name="dottedSkins" type="com.liferay.util.dao.hibernate.BooleanType"/>
<property name="roundedSkins" type="com.liferay.util.dao.hibernate.BooleanType"/>
<property name="greeting"/>
<property name="resolution"/>
<property name="refreshRate"/>
<property name="layoutIds"/>
<property name="loginDate"/>
<property name="loginIP"/>
<property name="lastLoginDate"/>
<property name="lastLoginIP"/>
<set name="groups" table="Users_Groups" lazy="true">
<key>
<column name="userId"/>
<column name="portalId"/>
</key>
<many-to-many class="com.liferay.portal.ejb.GroupHBM">
<column name="groupId"/>
<column name="portalId"/>
</many-to-many>
</set>
</class>


<class name="com.liferay.portal.ejb.GroupHBM" table="TCPS_Group_">

<composite-id name="primaryKey" class="com.liferay.portal.ejb.GroupPK">
<key-property name="groupId"/>
<key-property name="portalId"/>
</composite-id>
<property name="parentGroupId"/>
<property name="name"/>
<property name="layoutIds"/>
<property name="wikiNodeIds"/>
<set name="users" table="Users_Groups" lazy="true">
<key>
<column name="groupId"/>
<column name="portalId"/>
</key>
<many-to-many class="com.liferay.portal.ejb.UserHBM">
<column name="userId"/>
<column name="portalId"/>
</many-to-many>
</set>

</class>


Table Structure
---------------

CREATE TABLE TCPS_USER_ (
USERID VARCHAR2 (100) NOT NULL,
PORTALID VARCHAR2 (100) NOT NULL,
EMAILADDRESS VARCHAR2 (100),
LANGUAGEID VARCHAR2 (10) DEFAULT '',
TIMEZONEID VARCHAR2 (30) DEFAULT '',
SKINID VARCHAR2 (100) DEFAULT '1',
DOTTEDSKINS NUMBER (1) DEFAULT '0',
ROUNDEDSKINS NUMBER (1) DEFAULT '0',
GREETING VARCHAR2 (100) DEFAULT '',
RESOLUTION VARCHAR2 (100) DEFAULT '',
REFRESHRATE VARCHAR2 (100) DEFAULT '',
LAYOUTIDS VARCHAR2 (100) DEFAULT '',
LOGINDATE DATE,
LOGINIP VARCHAR2 (100) DEFAULT '',
LASTLOGINDATE DATE,
LASTLOGINIP VARCHAR2 (100) DEFAULT '',
FIRSTNAME VARCHAR2 (100),
MIDDLENAME VARCHAR2 (100),
LASTNAME VARCHAR2 (100),
PRIMARY KEY ( USERID, PORTALID )

CREATE TABLE TCPS_USERS_GROUPS (
USERID VARCHAR2 (100) NOT NULL,
GROUPID VARCHAR2 (100) NOT NULL,
PORTALID VARCHAR2 (100) NOT NULL,
CONSTRAINT PK_TCPS_USERS_GROUPS
PRIMARY KEY ( USERID, GROUPID, PORTALID )

ALTER TABLE TCPS_USERS_GROUPS ADD CONSTRAINT FK1
FOREIGN KEY (GROUPID, PORTALID)
REFERENCES CPSUSER.TCPS_GROUP_ (GROUPID, PORTALID) ;

ALTER TABLE TCPS_USERS_GROUPS ADD CONSTRAINT FK2
FOREIGN KEY (USERID, PORTALID)
REFERENCES CPSUSER.TCPS_USER_ (USERID, PORTALID) ;


CREATE TABLE TCPS_GROUP_ (
GROUPID VARCHAR2 (100) NOT NULL,
PORTALID VARCHAR2 (100) NOT NULL,
PARENTGROUPID VARCHAR2 (100),
NAME VARCHAR2 (100),
LAYOUTIDS VARCHAR2 (100) DEFAULT '',
WIKINODEIDS VARCHAR2 (100) DEFAULT '',
PRIMARY KEY ( GROUPID, PORTALID )


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 27, 2004 1:54 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
This is not possible in Hibernate. If you have the same column mapped twice in the same class, you are supposed to declare the property insert="false" update="false". But in this case that won't work, because only /part/ of the FK is duplicated. There are two possibe solutions:


(1) add userPortalId and groupPortalId columns (yick!)
(2) don't declare portalId as part of the <id> of all your classes

I gotta say that I can't quite understand why you would include portalId in all the PKs to begin with. You have what are essentially surrogate keys! Why confuse the issue by adding portalId in there. If you are trying to achieve some kind of extra referential integrity, I would suggest using a trigger to achieve that. I would not say that this relational model is a good practice.

interesting: I've just been testing various dbs to see if you can use subselects in check constraints to do this kind of referential integrity, but apparently not. - you need a trigger i guess.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 27, 2004 1:58 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
P.S. a third possibility is to declare portalId in all the PKs, and FK constraints, but just dont tell Hibernate that. That would work, I guess. Assuming the userId, groupId, etc, bits are unique on their own.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 07, 2004 1:27 am 
Hi ,
I am using Hibernate 2.1.3 .

we have a requirement where we need to store the version's of different entities. It is like we have a working copy and current copy.
There can be only one current copy at any time but any number of working copies. So to enable this at the relational model we have to attach VERSION_ID along with main entity ID.

But since Hibernate doesn't allow us to define the same column twice in the class we are unable to many useful features that Hibernate provides us out of the box like many-to-one ,many-to-many etc.. It works fine with one-to-many .I did talk to my DBA but they say its more hibernate issue rather than a relational model issue. I did see the other alternatives that
Gavin posted but in vain...

Below are the two mapping files.

<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>

<class
name="com.eds.edscs.mortgage.securityregister.domain.model.financials.asset.Asset"
table="SR_ASSETS"
dynamic-update="false"
>

<composite-id name="compositeKey" class="com.eds.edscs.mortgage.securityregister.common.CompositeKey">
<key-property name = "key1" column="ASSET_ID"/>
<key-property name = "key2" column="VERSION_ID"/>
</composite-id>



<joined-subclass
name="com.eds.edscs.mortgage.securityregister.domain.model.financials.asset.RealEstate"
table="SR_REAL_ESTATES"
dynamic-update="false"
>

<key>
<column name="ASSET_ID"/>
<column name="VERSION_ID"/>
</key>


<component name="location"
class="com.eds.edscs.mortgage.securityregister.domain.model.financials.asset.Location">

<component name="address"
class="com.eds.edscs.mortgage.securityregister.domain.model.address.Address">
<property name="addressId" column="ADDRESS_ID"/>
</component>

</component>


<!--
Mapping for Address Details
-->

<!--
<component name="location"
class="com.eds.edscs.mortgage.securityregister.domain.model.financials.asset.Location">


<many-to-one name="address"
class="com.eds.edscs.mortgage.securityregister.domain.model.address.Address"
cascade="all"
outer-join="auto"
insert="false"
update="false">

<column name="ADDRESS_ID"/>
<column name="VERSION_ID"/>

</many-to-one>

</component>
-->




</joined-subclass>


</class>

</hibernate-mapping>



<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>

<class
name="com.eds.edscs.mortgage.securityregister.domain.model.address.Address"
table="SR_ADDRESSES"
dynamic-update="false"
>

<composite-id name="compositeKey" class="com.eds.edscs.mortgage.securityregister.common.CompositeKey">
<key-property name = "key1" column="ADDRESS_ID"/>
<key-property name = "key2" column="VERSION_ID"/>
</composite-id>


</class>

</hibernate-mapping>


Top
  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.