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: duplicate import - only if I have <joined-subclass...>
PostPosted: Thu Jul 28, 2005 7:03 pm 
Beginner
Beginner

Joined: Thu Jul 28, 2005 6:40 pm
Posts: 29
Hi;

I have a single hibernate.cfg.xml that has a single mapping:
<mapping resource="net/windward/store/demo/DemoRequest.hbm.xml"/>

This mapping has two classes. I have Person and DemoRequest and the DemoRequest class extends the Person class.

If I do not put the following in the <class name="DemoRequest ...> node:
<joined-subclass name="net.windward.store.util.Person" table="Person">
<key column="personId"/>
</joined-subclass>

Then I can run and access both the Person and DemoRequest objects. But if I have the joined-subclass in, then I get the exception.

stack trace:
INFO (HbmBinder.java:260) - "Mapping class: net.windward.store.util.Person -> Person"
INFO (HbmBinder.java:260) - "Mapping class: net.windward.store.demo.DemoRequest -> DemoRequest"
ERROR (Configuration.java:365) - "Could not compile the mapping document"
org.hibernate.MappingException: duplicate import: net.windward.store.util.Person
at org.hibernate.cfg.Mappings.addImport(Mappings.java:105)
at org.hibernate.cfg.HbmBinder.bindPersistentClassCommonValues(HbmBinder.java:541)
at org.hibernate.cfg.HbmBinder.bindClass(HbmBinder.java:488)
at org.hibernate.cfg.HbmBinder.bindJoinedSubclass(HbmBinder.java:759)
at org.hibernate.cfg.HbmBinder.handleJoinedSubclass(HbmBinder.java:1879)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:1802)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:1728)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:318)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:236)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:152)
at org.hibernate.cfg.Configuration.add(Configuration.java:362)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:400)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:449)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1263)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1235)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1217)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1184)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1112)
at net.windward.store.demo.test.TestAll.main(TestAll.java:22)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:78)

complete DemoRequest.hbm.xml:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping auto-import="false">

<class name="net.windward.store.util.Person">
<id name="personId" type="int">
<!-- <generator class="native"/> -->
</id>

<property name="name" type="string"/>
<property name="title" type="string"/>
<property name="company" type="string"/>
<property name="address1" type="string"/>
<property name="address2" type="string"/>
<property name="city" type="string"/>
<property name="state" type="string"/>
<property name="postalCode" type="string"/>
<property name="country" type="string"/>
<property name="phone" type="string"/>
<property name="email" type="string"/>
</class>

<class name="net.windward.store.demo.DemoRequest">
<id name="demoRequestId" type="int">
<generator class="native"/>
</id>

<!-- bugbug - make type -->
<property name="whereHeard" type="string"/>
<property name="createDate" type="date"/>
<property name="ipAddress" type="string"/>
<property name="trackingUniqueId" type="string"/>
<property name="trackingSource" type="string"/>
<property name="trackingId" type="string"/>
<property name="trackingReferrer" type="string"/>
<!-- end type -->

<property name="mailPing" type="short"/>
<property name="sendInfo" type="boolean"/>
<property name="ignore" type="boolean"/>
<property name="freebie" type="boolean"/>

<joined-subclass name="net.windward.store.util.Person" table="Person">
<key column="personId"/>
</joined-subclass>
</class>

</hibernate-mapping>

??? - thanks - dave


Top
 Profile  
 
 Post subject: Re: duplicate import - only if I have <joined-subclass...
PostPosted: Thu Jul 28, 2005 7:18 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
Look at the examples again in the refernce document.
You do not need a <class> and a <joined-subclass> mapping for DemoRequest. Just the <joined-subclass> definition.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 28, 2005 8:24 pm 
Beginner
Beginner

Joined: Thu Jul 28, 2005 6:40 pm
Posts: 29
Thank you - I didn't realize it was there only.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 29, 2005 10:39 pm 
Beginner
Beginner

Joined: Fri Jul 29, 2005 2:11 pm
Posts: 21
I'm having a similar problem; what am I doing wrong here? I'm getting an a duplicate import error on the Program.hbm.xml file shown below.


Code:
<hibernate-mapping>
    <class name="Program" table="PROGRAM">
      <id name="programId" column="PGM_ID">
         <generator class="assigned"/>
      </id>
      <property name="programShortName" column="PGM_SHT_NME"/>
      <property name="programLongName" column="PGM_LONG_NME"/>
   </class>
</hibernate-mapping>

<hibernate-mapping>
   <class name="DefaultPortfolio" table="DEFAULT_PORTFOLIO">
      <id name="portfolioId" column="PORT_ID">
         <generator class="assigned"/>
      </id>
      <property name="systemId" column="SYS_ID"/>
      <property name="programId" column="PGM_ID"/>

       <joined-subclass name="Program" table="PROGRAM_REF">
         <key column="PGM_ID"/>
         <property name="programLongName" column="PGM_LONG_NME" type="java.lang.String" />
       </joined-subclass>
   </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 29, 2005 10:57 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
biguniverse wrote:
I'm having a similar problem; what am I doing wrong here? I'm getting an a duplicate import error on the Program.hbm.xml file shown below.


Code:
<hibernate-mapping>
    <class name="Program" table="PROGRAM">
      <id name="programId" column="PGM_ID">
         <generator class="assigned"/>
      </id>
      <property name="programShortName" column="PGM_SHT_NME"/>
      <property name="programLongName" column="PGM_LONG_NME"/>
   </class>
</hibernate-mapping>

<hibernate-mapping>
   <class name="DefaultPortfolio" table="DEFAULT_PORTFOLIO">
      <id name="portfolioId" column="PORT_ID">
         <generator class="assigned"/>
      </id>
      <property name="systemId" column="SYS_ID"/>
      <property name="programId" column="PGM_ID"/>

       <joined-subclass name="Program" table="PROGRAM_REF">
         <key column="PGM_ID"/>
         <property name="programLongName" column="PGM_LONG_NME" type="java.lang.String" />
       </joined-subclass>
   </class>
</hibernate-mapping>


You're defining two objects with the name "Program" One for table PROGRAM and one, the joined-subclass, for table PROGRAM_REF. Each class, joined-subclass, etc... must have a unique name.

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 29, 2005 11:00 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Actually, each entity must have a unique entity-name, which by default is the same as the class name. It is possible to map a class twice, you just have to explicitly specify the entity-name.


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.