-->
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.  [ 6 posts ] 
Author Message
 Post subject: Recursive association with Hibernate
PostPosted: Mon Apr 05, 2010 4:50 pm 
Newbie

Joined: Wed Mar 24, 2010 2:58 am
Posts: 10
Location: Livorno,Italy
I have to map a recursive association: i mean that i have to persist one POJO, Part,which consist of other Part object (a collection).
How can i map that with annotations and what type of association i have to use?
Thank you and sorry for my bad english,

Daniel


Top
 Profile  
 
 Post subject: Re: Recursive association with Hibernate
PostPosted: Tue Apr 06, 2010 3:07 am 
Regular
Regular

Joined: Wed Mar 10, 2010 4:48 am
Posts: 106
Example:
Code:
<hibernate-mapping>
   <class name="Measurement" table="measurements">
      <id name="id" column="id">
         <generator class="assigned" />
      </id>

      <many-to-one name="smallest" class="Measurement" column="smallest" />

      <set name="measurements" table="measurements" cascade="delete">
         <key column="smallest" />
         <one-to-many class="Measurement" />
      </set>
   </class>
</hibernate-mapping>

Smallest is a FK to a parent object of Measurement. The set measurements contains the childrens.


Top
 Profile  
 
 Post subject: Re: Recursive association with Hibernate
PostPosted: Sat Apr 17, 2010 6:34 pm 
Newbie

Joined: Wed Mar 24, 2010 2:58 am
Posts: 10
Location: Livorno,Italy
i've tried, it says to me

Quote:
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Programmi/NetBeans%206.7.1/slf4j-1.5.8/slf4j-simple-1.5.8.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Programmi/NetBeans%206.7.1/hibernate-annotations-3.4.0.GA/lib/test/slf4j-log4j12.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
31 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.3.2.GA
31 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
62 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
78 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
265 [main] INFO org.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml
265 [main] INFO org.hibernate.cfg.Configuration - Configuration resource: /hibernate.cfg.xml
546 [main] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : prova.hbm.xml
750 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: Prova -> prova
968 [main] INFO org.hibernate.cfg.Configuration - Configured SessionFactory: null
984 [main] INFO org.hibernate.cfg.HbmBinder - Mapping collection: Prova.prove -> prova
Exception in thread "main" org.hibernate.MappingException: Duplicate property mapping of codice found in Prova
at org.hibernate.mapping.PersistentClass.checkPropertyDuplication(PersistentClass.java:477)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:467)
at org.hibernate.mapping.RootClass.validate(RootClass.java:215)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1149)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1334)
at Main.main(Main.java:22)
Java Result: 1


This is the xml mapping file:

Code:
<?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="Prova" table="prova">
        <id name="id" type="int"/>
         <property name="codice" type="int"/>
              <property name="nome" type="string"/>
           <many-to-one name="codice" class="Prova" column="codice"/>

<set name="prove" table="prova" >
         <key column="codice" />
         <one-to-many class="Prova" />
      </set>

           

     
    </class>
</hibernate-mapping>


Why it doesn't found? i don't understand...
Thank you,
Daniel


Top
 Profile  
 
 Post subject: Re: Recursive association with Hibernate
PostPosted: Mon Apr 19, 2010 3:31 am 
Regular
Regular

Joined: Wed Mar 10, 2010 4:48 am
Posts: 106
Black Phoenix wrote:
If you get an error like this read it.
Quote:
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Programmi/NetBeans%206.7.1/slf4j-1.5.8/slf4j-simple-1.5.8.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Programmi/NetBeans%206.7.1/hibernate-annotations-3.4.0.GA/lib/test/slf4j-log4j12.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
...


It means there are two slf4j bindings found and it doesn't know which to use.
Solution: remove one of them.


Top
 Profile  
 
 Post subject: Re: Recursive association with Hibernate
PostPosted: Tue Apr 20, 2010 2:02 pm 
Newbie

Joined: Wed Mar 24, 2010 2:58 am
Posts: 10
Location: Livorno,Italy
I think this isn't the problem, because other applications give me the same slf4j error but are ok.
I think the real problem is in this part:
Code:
Exception in thread "main" org.hibernate.MappingException: Duplicate property mapping of codice found in Prova
at org.hibernate.mapping.PersistentClass.checkPropertyDuplication(PersistentClass.java:477)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:467)
at org.hibernate.mapping.RootClass.validate(RootClass.java:215)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1149)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1334)
at Main.main(Main.java:22)
Java Result: 1

Exception in thread "main" org.hibernate.MappingException: Duplicate property mapping of codice found in Prova

Someone can help me?
Thank you,
Daniel


Top
 Profile  
 
 Post subject: Re: Recursive association with Hibernate
PostPosted: Wed Apr 21, 2010 3:13 am 
Regular
Regular

Joined: Wed Mar 10, 2010 4:48 am
Posts: 106
Black Phoenix wrote:
<class name="Prova" table="prova">
<id name="id" type="int"/>
<property name="codice" type="int"/>
<property name="nome" type="string"/>
<many-to-one name="codice" class="Prova" column="codice"/>

<set name="prove" table="prova" >
<key column="codice" />
<one-to-many class="Prova" />
</set>
</class>
Quote:
Exception in thread "main" org.hibernate.MappingException: Duplicate property mapping of codice found in Prova

You have two properties called codice, so if you need both you should rename one of them.


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