-->
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: Repeated Column in Mapping
PostPosted: Tue Sep 20, 2005 7:56 pm 
Newbie

Joined: Wed Jul 13, 2005 1:38 pm
Posts: 3
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.05 and 3.1b3

Mapping documents:
<hibernate-mapping
>
<class
name="org.appfuse.model.ModelB"
table="tst_b"
>

<id
name="id"
column="id"
type="java.lang.Long"
unsaved-value="null"
>
<generator class="native">
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-ModelB.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>

<version
name="version"
column="version"
type="java.lang.Integer"
/>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-ModelB.xml
containing the additional properties and place it in your merge dir.
-->

</class>

</hibernate-mapping>


Here's modela.hbm.xml

<?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
>
<class
name="org.appfuse.model.ModelA"
table="tst_b"
>

<id
name="id"
column="id"
type="java.lang.Long"
unsaved-value="null"
>
<generator class="native">
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-ModelA.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>

<version
name="version"
column="version"
type="java.lang.Integer"
/>

<many-to-one
name="modelBList"
class="org.appfuse.model.ModelB"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="id"
/>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-ModelA.xml
containing the additional properties and place it in your merge dir.
-->

</class>

</hibernate-mapping>


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

Full stack trace of any exception that occurs:
[junit] Error creating bean with name 'sessionFactory' defined in file [C:\tools\eclipse\eclipse
-data\workspace\test\build\dao\gen\META-INF\applicationContext-hibernate.xml]: Initialization of bea
n failed; nested exception is org.hibernate.MappingException: Repeated column in mapping for entity:
org.appfuse.model.ModelA column: id (should be mapped with insert="false" update="false")
[junit] org.springframework.beans.factory.BeanCreationException: Error creating bean with name '
sessionFactory' defined in file [C:\tools\eclipse\eclipse-data\workspace\test\build\dao\gen\META-INF
\applicationContext-hibernate.xml]: Initialization of bean failed; nested exception is org.hibernate
.MappingException: Repeated column in mapping for entity: org.appfuse.model.ModelA column: id (shoul
d be mapped with insert="false" update="false")
[junit] org.hibernate.MappingException: Repeated column in mapping for entity: org.appfuse.model
.ModelA column: id (should be mapped with insert="false" update="false")
Name and version of the database you are using:

The generated SQL (show_sql=true):
MySQL 4.1

Debug level Hibernate log excerpt:
na


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 20, 2005 9:28 pm 
Senior
Senior

Joined: Wed Jul 13, 2005 4:31 pm
Posts: 142
Location: Seattle, WA
ModelA has id and version
ModelB has id and version and a reference to ModelA

In modelB
Code:
<many-to-one
name="modelBList"
class="org.appfuse.model.ModelB"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="id"
/>


which implies that the reference to ModelA is the same as ModelB id.
IF that is the case, the association is not many-to-one, but one-to-one.

Maybe you meant to give different name to column for many-to-one relationship to modelB


Top
 Profile  
 
 Post subject: now I see
PostPosted: Wed Sep 21, 2005 3:28 pm 
Newbie

Joined: Wed Jul 13, 2005 1:38 pm
Posts: 3
Thanks, I think I now see my problem. I needed to add some arbitrary column name and not use the id column. -Bruce


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.