-->
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.  [ 3 posts ] 
Author Message
 Post subject: Duplicate column error
PostPosted: Mon Mar 12, 2007 5:35 pm 
Newbie

Joined: Wed Jul 27, 2005 3:44 pm
Posts: 12
Location: Los Angeles, CA
Hello.

I've a problem with Hibernate mapping.
I've three tables:
============
VendorAccount:
id bigint(identity) primary key
name varchar(50)
============
BiddingSettings:
accountId bigint references VendorAccount.id
distributionType char(1) references DistributionType.code
bidSunday bit
bitMonday bit
bidXXX bit etc.
============
DistributionType:
code char(1) primary key
description varchar(50)
========================================
So BiddingSettings has composite primary key (accountID+distributionType) and it's immutable. I want to access it unidirectionally from VendorAccount as
Code:
    settings = vendorAccount.getBiddingSettings().get(distributionType);

so <map> is ideal for me.
Problem is that when Factory is initializing hibernate it gives error:
Quote:
org.hibernate.MappingException: Repeated column in mapping for entity: com.business.sem.BiddingSchedule column: accountId (should be mapped with insert="false" update="false")


Why duplicate column? Has anyone been able to create a map pointing to a table with composite key? My compsite key is immutable, that's why I didn't want to create an identity column in the BiddingSettings table.

Hibernate version: 3.0.5

Mapping documents:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.business.sem" default-cascade="save-update" default-lazy="true">
<class name="VendorAccount" lazy="true" select-before-update="false" table="VendorAccount">
<meta attribute="implements">com.business.sem.IEntityState</meta>
<id name="id" type="java.lang.Long" column="id">
<meta attribute="use-in-tostring">true</meta>
<generator class="identity" />
</id>
<property name="name" column="name" length="50" type="java.lang.String" not-null="true">
<meta attribute="use-in-tostring">true</meta>
<meta attribute="field-description">Name of the account</meta>
</property>
<property name="quickCode" column="quickCode" length="9" type="java.lang.String" not-null="true">
<meta attribute="use-in-tostring">true</meta>
<meta attribute="field-description">1-5 character code of the account for faster SQL</meta>
</property>
<property name="logonURL" column="logonURL" type="java.lang.String" length="1024" not-null="false">
<meta attribute="field-description">[Maybe] URL of the logon page</meta>
</property>
<property name="userName" column="username" type="java.lang.String" length="50" not-null="false">
<meta attribute="field-description">[Maybe] user's logon</meta>
</property>
<property name="password" column="password" type="java.lang.String" length="40" not-null="false">
<meta attribute="field-description">[Maybe] user's account password</meta>
</property>
<property name="key1" column="key1" type="java.lang.String" length="128" not-null="false">
<meta attribute="field-description">[Maybe] Additional information to get into account, e.g. account key</meta>
</property>
<property name="key2" column="key2" type="java.lang.String" length="128" not-null="false">
<meta attribute="field-description">[Maybe] Additional information to get into account, e.g. account key</meta>
</property>
<property name="minBid" column="minBid" type="java.math.BigDecimal" scale="2" not-null="false">
<meta attribute="field-description">[Maybe] Minimum bid for a keyword allowed in this account</meta>
</property>

<map name="biddingSchedule" outer-join="true" table="BiddingSchedule">
<key column="accountId" not-null="true" unique="false" update="false" />
<map-key-many-to-many class="com.business.sem.DistributionType" column="distributionType" />
<one-to-many class="BiddingSchedule" />
<!--composite-element class="SEMBEEBiddingSchedule">
<many-to-one name="account" column="accountId" class="VendorAccount" not-null="true" />
<many-to-one name="distribType" column="distributionType" class="DistributionType" not-null="true" />
<property name="bidSunday" column="bidSun" type="java.lang.Boolean" not-null="true" />
<property name="bidMonday" column="bidMon" type="java.lang.Boolean" not-null="true" />
<property name="bidTuesday" column="bidTue" type="java.lang.Boolean" not-null="true" />
<property name="bidWednesday" column="bidWed" type="java.lang.Boolean" not-null="true" />
<property name="bidThursday" column="bidThu" type="java.lang.Boolean" not-null="true" />
<property name="bidFriday" column="bidFri" type="java.lang.Boolean" not-null="true" />
<property name="bidSaturday" column="bidSat" type="java.lang.Boolean" not-null="true" />
</composite-element>-->
</map>

<property name="lastUpdate" column="lastUpdate" type="java.sql.Timestamp" not-null="false" update="false" insert="false" />

</hibernate-mapping>

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.business.sem" default-cascade="save-update" default-lazy="true">
<class name="BiddingSchedule" table="BiddingSchedule" lazy="true" select-before-update="false">
<composite-id name="pk" class="BiddingSchedulePK">
<meta attribute="use-in-tostring">true</meta>
<key-many-to-one name="account" column="accountId" class="VendorAccount">
<meta attribute="use-in-tostring">true</meta>
</key-many-to-one>
<key-many-to-one name="distributionType" column="distributionType" class="DistributionType">
<meta attribute="use-in-tostring">true</meta>
</key-many-to-one>
</composite-id>
<natural-id mutable="false">
<many-to-one name="account" column="accountId" class="VendorAccount" />
<many-to-one name="distribution" column="distributionType" class="DistributionType" />
</natural-id>
<property name="bidSunday" column="bidSun" type="java.lang.Boolean" not-null="true" />
<property name="bidMonday" column="bidMon" type="java.lang.Boolean" not-null="true" />
<property name="bidTuesday" column="bidTue" type="java.lang.Boolean" not-null="true" />
<property name="bidWednesday" column="bidWed" type="java.lang.Boolean" not-null="true" />
<property name="bidThursday" column="bidThu" type="java.lang.Boolean" not-null="true" />
<property name="bidFriday" column="bidFri" type="java.lang.Boolean" not-null="true" />
<property name="bidSaturday" column="bidSat" type="java.lang.Boolean" not-null="true" />

</class>
</hibernate-mapping>



Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:
Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: com.business.sem.SEMBEEBiddingSchedule column: accountId (should be mapped with insert="false" update="false")
at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:504)
at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:526)
at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:544)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:335)
at org.hibernate.mapping.RootClass.validate(RootClass.java:188)
at org.hibernate.cfg.Configuration.validate(Configuration.java:839)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1000)
at com.business.sem.base._BaseRootDAO.initialize(_BaseRootDAO.java:54)
at com.business.sem.h3.H3DatastoreFactory.<init>(H3DatastoreFactory.java:12)
at com.business.sem.h3.H3DatastoreFactory.getInstance(H3DatastoreFactory.java:21)
at com.business.sem.util.Utils.<clinit>(Utils.java:19)

Name and version of the database you are using:
SQLServer 2000

The generated SQL (show_sql=true):
N/A

Debug level Hibernate log excerpt:
14:07:30,963 INFO [STDOUT] 14:07:30,963 INFO [Configuration] processing collection mappings
14:07:30,963 INFO [STDOUT] 2531 [http-0.0.0.0-8080-1] INFO org.hibernate.cfg.Configuration - processing collection mappings
14:07:30,963 INFO [STDOUT] 2531 [http-0.0.0.0-8080-1] DEBUG org.hibernate.cfg.HbmBinder - Second pass for collection: com.business.sem.VendorAccount.sembeeBiddingSchedule
14:07:30,963 INFO [STDOUT] 14:07:30,963 INFO [HbmBinder] Mapping collection: com.business.sem.VendorAccount.sembeeBiddingSchedule -> SEMBEEBiddingSchedule
14:07:30,963 INFO [STDOUT] 2531 [http-0.0.0.0-8080-1] INFO org.hibernate.cfg.HbmBinder - Mapping collection: com.business.sem.VendorAccount.sembeeBiddingSchedule -> SEMBEEBiddingSchedule
14:07:30,963 INFO [STDOUT] 2531 [http-0.0.0.0-8080-1] DEBUG org.hibernate.cfg.HbmBinder - Mapped collection key: accountId, index: distributionType, one-to-many: com.business.sem.SEMBEEBiddingSchedule


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html
Code:
[quote][/quote]

_________________
Maxim Senin
Custom Software Development for the Enterprise
http://www.supremistic.com/


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 13, 2007 12:13 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Hi msenin
Try to remove one or use insert="false" update="false" with composite key

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.business.sem" default-cascade="save-update" default-lazy="true">
<class name="BiddingSchedule" table="BiddingSchedule" lazy="true" select-before-update="false">
<composite-id name="pk" class="BiddingSchedulePK">
<meta attribute="use-in-tostring">true</meta>
<key-many-to-one name="account" column="accountId" class="VendorAccount"> <meta attribute="use-in-tostring">true</meta>
</key-many-to-one>
<key-many-to-one name="distributionType" column="distributionType" class="DistributionType">
<meta attribute="use-in-tostring">true</meta>
</key-many-to-one>
</composite-id>
<natural-id mutable="false">
<many-to-one name="account" column="accountId" class="VendorAccount" /> <many-to-one name="distribution" column="distributionType" class="DistributionType" />
</natural-id>
<property name="bidSunday" column="bidSun" type="java.lang.Boolean" not-null="true" />
<property name="bidMonday" column="bidMon" type="java.lang.Boolean" not-null="true" />
<property name="bidTuesday" column="bidTue" type="java.lang.Boolean" not-null="true" />
<property name="bidWednesday" column="bidWed" type="java.lang.Boolean" not-null="true" />
<property name="bidThursday" column="bidThu" type="java.lang.Boolean" not-null="true" />
<property name="bidFriday" column="bidFri" type="java.lang.Boolean" not-null="true" />
<property name="bidSaturday" column="bidSat" type="java.lang.Boolean" not-null="true" />

</class>
</hibernate-mapping>

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 13, 2007 3:02 am 
Newbie

Joined: Wed Jul 27, 2005 3:44 pm
Posts: 12
Location: Los Angeles, CA
dharmendra.pandey wrote:
Hi msenin
Try to remove one or use insert="false" update="false" with composite key

I am unable to add insert="false" update="false" to compsote key because they are not defined in XML DTS.

I tried any combination of field definitions and it seems that ANY reference to accountId or distributionType in BiddingSchedule.hbm.xml will cause this error - as long as VendorAccount.hbm.xml also refers to accountId and distributionType in the MAP tag.

My temporary solution to the problem was to removing references to accountId and distributionType columns from BiddingSchedule.hbm.xml entirely and adding a synthetic key column "id" int identity to the BiddingScheduleTable and to the class mapping. It works as long as there is not reference to these two columns in BiddingSchedule.hbm.xml, except that I don't like it. I was hoping it is possible to create a "map" mapping to any entity, even ifit has a composite natural key. It just happens in this particular case that parts of the composite key are collection key and the map key in VendorAccount.hbm.xml

Has anyone got a better solution? The composite key here is immutable, so I really don't need a synchetic ID. A syncheic id is helpful when any side of the relationship may change in the future or for mapping many-to-many relationships but this is not the case. This one is more like mapping a class hierarchy: for each account there are BiddingSchedules of different distributionTypes. That's why I would like to use MAP mapping.

_________________
Maxim Senin
Custom Software Development for the Enterprise
http://www.supremistic.com/


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