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.  [ 8 posts ] 
Author Message
 Post subject: Duplicate property exception during buildSessionFactory()
PostPosted: Tue Aug 09, 2005 1:00 pm 
Regular
Regular

Joined: Wed May 11, 2005 11:57 pm
Posts: 80
I'm having a problem any time that I have more than a single one-to-many not-null relationship to an entity.

In this case, 'Instructor' and 'Classroom' have mandatory one-to-many relationships to 'Course'. I recently changed my mapping file to add a not-null restraint on the foreign keys in the Course table, and since doing that, Hibernate will not create a SessionFactory. I don't want to go back to the old config because it's very valuable to have a not-null constraint on the foreign keys.

My guess is that Hibernate internally creates a property called '_coursesBackref' for each mandatory relationship with 'course' as its destination, and when there are multiple relationships, it fails validation because the properties have the same name. Changing the internal name to something like '_coursesForInstructorBackref' and '_coursesForClassroomBackref' seems like it would solve it, but I'm hoping to get some help and/or confirmations of this problem before I try to start fixing the source code.

Hibernate version: 3.05

Mapping documents:
Code:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.prosc.test" default-cascade="lock" default-access="field">
   <class lazy="false" name="Course">
      <id name="id" type="java.lang.Long" unsaved-value="null">
         <generator class="native"/>
      </id>
      <property name="name" type="java.lang.String"/>
      <property name="courseNumber" type="java.lang.String"/>
      <property name="courseDescription" type="java.lang.String"/>
      <many-to-one name="classroom" column="classroomId" not-null="true" update="false" insert="false"/>
      <many-to-one name="instructor" column="instructorId" not-null="true" update="false" insert="false"/>
      <set inverse="false" name="students" lazy="true" table="JoinCourseStudent">
         <key column="coursesId"/>
         <many-to-many column="studentsId" class="Student"/>
      </set>
   </class>
</hibernate-mapping>

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.prosc.test" default-cascade="lock" default-access="field">
   <class lazy="false" name="Instructor">
      <id name="id" type="java.lang.Long" unsaved-value="null">
         <generator class="native"/>
      </id>
      <property name="firstName" type="java.lang.String"/>
      <property name="lastName" type="java.lang.String"/>
      <property name="title" type="java.lang.String"/>
      <list name="courses" lazy="true" inverse="false">
         <key column="instructorId" not-null="true"/>
         <index column="sortOrderForinstructor"/>
         <one-to-many class="Course"/>
      </list>
   </class>
</hibernate-mapping>

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.prosc.test" default-cascade="lock" default-access="field">
   <class lazy="false" name="Classroom">
      <id name="id" type="java.lang.Long" unsaved-value="null">
         <generator class="native"/>
      </id>
      <property name="floor" type="java.lang.String"/>
      <property name="building" type="java.lang.String"/>
      <list name="courses" lazy="true" inverse="false">
         <key column="classroomId" not-null="true"/>
         <index column="sortOrderForclassroom"/>
         <one-to-many class="Course"/>
      </list>
   </class>
</hibernate-mapping>



Code between sessionFactory.openSession() and session.close():
N/A - this happens during building the session factory. Here is the code:
Code:
      Configuration config = new Configuration();
      config.configure();
      sessionFactory = config.buildSessionFactory();


Full stack trace of any exception that occurs:
Aug 9, 2005 12:50:49 PM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing foreign key constraints

java.lang.ExceptionInInitializerError
at com.prosc.test.OneToManyTest.testBadAdd(OneToManyTest.java:42)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at com.intellij.rt.execution.junit2.JUnitStarter.main(JUnitStarter.java:31)
Caused by: org.hibernate.MappingException: duplicate property mapping: _coursesBackref
at org.hibernate.mapping.PersistentClass.checkPropertyDuplication(PersistentClass.java:344)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:334)
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.prosc.test.TestUtils.<clinit>(TestUtils.java:33)
... 19 more

Name and version of the database you are using: MySQL 4.10

The generated SQL (show_sql=true): N/A, never gets to that point

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 09, 2005 4:26 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Your analysis sounds correct, but reduce it to the minimum testcase and submit it to jira (with a patch will be a good thing)

/max

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 09, 2005 4:37 pm 
Regular
Regular

Joined: Wed May 11, 2005 11:57 pm
Posts: 80
max wrote:
Your analysis sounds correct, but reduce it to the minimum testcase and submit it to jira (with a patch will be a good thing)

/max


Thanks, I will do that.


Top
 Profile  
 
 Post subject: JIRA number ?
PostPosted: Sun Oct 09, 2005 1:57 pm 
Newbie

Joined: Sun Oct 02, 2005 3:15 pm
Posts: 5
Location: Brasilia - Brazil
If this issue was submitted, please what is the jira number ?

thansk

Claudio


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 09, 2005 1:59 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
no issue were never created for this AFAIK

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Re: JIRA number ?
PostPosted: Mon Oct 10, 2005 1:38 pm 
Regular
Regular

Joined: Wed May 11, 2005 11:57 pm
Posts: 80
claudius wrote:
If this issue was submitted, please what is the jira number ?

thansk

Claudio


I never submitted this on Jira - the last time I spent a bunch of time putting together a submission with a patch, it was rejected without comment, and I'm not interested in wasting more time. I ended up modifying the Hibernate source code to fix the bug. If you'd like the patch, let me know your e-mail address and I'll send it directly to you.

--Jesse


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 12, 2005 5:02 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Hi,

I haven't been able to find an issue with a patch that were rejected with no comment without being redundant....(we do get ALOT of that and sometimes we just have to do short process - dont feel bad about that)

If you have a testcase and a fix for this use please put it in jira and i will apply it (if its correct of course ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Re: Duplicate property exception during buildSessionFactory()
PostPosted: Thu Jul 07, 2011 6:41 am 
Newbie

Joined: Thu Jul 07, 2011 6:39 am
Posts: 2
Hi, did you ever get this resolved. We're having the same issue.

JJ


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