-->
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.  [ 1 post ] 
Author Message
 Post subject: Problem on hibernate extend class mapping
PostPosted: Wed Mar 09, 2005 11:48 pm 
Newbie

Joined: Wed Mar 09, 2005 11:39 pm
Posts: 1
Situation is:
I have downloaded an external lib with parent class X (eg. com.company.Sample), then I wrote a class Y (eg. my.classes.Sample) that extends class X and need to map it in hibernate.
Since the external lib fetches class X directly I must declare <class> tag in .hbm.xml file, so I declare class Y as <subclass> with class X declaration.


Problem is:
Since class X and class Y has the sample name "Sample", hibernate tends to consider that "duplicate" and throw "duplicate import" error.


How can I solve the above problem?



Hibernate version:
Hibernate 2
Mapping documents:

<hibernate-mapping>
<class
name="de.nava.informa.impl.hibernate.Channel"
table="CHANNELS"
dynamic-update="false"
dynamic-insert="false"
polymorphism="explicit"
>

<id
name="intId"
column="CHANNEL_ID"
type="integer"
unsaved-value="-1"
>
<generator class="native">
</generator>
</id>

<property
name="title"
type="java.lang.String"
update="true"
insert="true"
column="TITLE"
not-null="true"
/>

<property
name="description"
type="java.lang.String"
update="true"
insert="true"
column="DESCRIPTION"
/>

<property
name="locationString"
type="string"
update="true"
insert="true"
column="LOCSTRING"
/>

<property
name="site"
type="java.net.URL"
update="true"
insert="true"
column="SITE"
/>

<property
name="creator"
type="java.lang.String"
update="true"
insert="true"
column="CREATOR"
/>

<property
name="publisher"
type="java.lang.String"
update="true"
insert="true"
column="PUBLISHER"
/>

<property
name="language"
type="java.lang.String"
update="true"
insert="true"
column="LANGUAGE"
/>

<property
name="formatString"
type="string"
update="true"
insert="true"
column="FORMAT"
/>

<set
name="groups"
table="CAT_GROUP_CHANNEL"
lazy="true"
inverse="true"
cascade="none"
sort="unsorted"
>

<key
column="CHANNEL_ID"
/>

<many-to-many
class="de.nava.informa.impl.hibernate.ChannelGroup"
column="GROUP_ID"
outer-join="auto"
/>

</set>

<bag
name="items"
table="ITEMS"
lazy="false"
inverse="true"
cascade="all"
>

<key
column="CHANNEL_ID"
/>

<one-to-many
class="de.nava.informa.impl.hibernate.Item"
/>
</bag>

<many-to-one
name="image"
class="de.nava.informa.impl.hibernate.Image"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="IMAGE_ID"
not-null="false"
/>

<many-to-one
name="textInput"
class="de.nava.informa.impl.hibernate.TextInput"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="TEXTINPUT_ID"
not-null="false"
/>

<property
name="copyright"
type="java.lang.String"
update="true"
insert="true"
column="COPYRIGHT"
/>

<property
name="rating"
type="java.lang.String"
update="true"
insert="true"
column="RATING"
/>

<many-to-one
name="cloud"
class="de.nava.informa.impl.hibernate.Cloud"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="CLOUD_ID"
not-null="false"
/>

<property
name="generator"
type="java.lang.String"
update="true"
insert="true"
column="GENERATOR"
/>

<property
name="docs"
type="java.lang.String"
update="true"
insert="true"
column="DOCS"
/>

<property
name="ttl"
type="int"
update="true"
insert="true"
column="TTL"
/>

<bag
name="categories"
table="CAT_CHANNEL_LINK"
lazy="true"
inverse="false"
cascade="none"
>

<key
column="CHANNEL_ID"
/>

<many-to-many
class="de.nava.informa.impl.hibernate.Category"
column="CATEGORY_ID"
outer-join="auto"
/>

</bag>

<property
name="lastUpdated"
type="java.util.Date"
update="true"
insert="true"
column="LAST_UPDATED"
/>

<property
name="lastBuildDate"
type="java.util.Date"
update="true"
insert="true"
column="LAST_BUILD_DATE"
/>

<property
name="pubDate"
type="java.util.Date"
update="true"
insert="true"
column="PUB_DATE"
/>

<property
name="updatePeriod"
type="java.lang.String"
update="true"
insert="true"
column="UPDATE_PERIOD"
/>

<property
name="updateFrequency"
type="int"
update="true"
insert="true"
column="UPDATE_FREQUENCY"
/>

<property
name="updateBase"
type="java.util.Date"
update="true"
insert="true"
column="UPDATE_BASE"
/>

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

<subclass name="com.newsy.channel.model.Channel" extends="de.nava.informa.impl.hibernate.Channel">
<property name="subscriptionNum" type="long"/>
</subclass>

</class>

</hibernate-mapping>

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

Full stack trace of any exception that occurs:

net.sf.hibernate.MappingException: duplicate import: Channel
at net.sf.hibernate.cfg.Mappings.addImport(Mappings.java:85)
at net.sf.hibernate.cfg.Binder.bindClass(Binder.java:127)
at net.sf.hibernate.cfg.Binder.bindSubclass(Binder.java:162)
at net.sf.hibernate.cfg.Binder.handleSubclass(Binder.java:1095)
at net.sf.hibernate.cfg.Binder.propertiesFromXML(Binder.java:1056)
at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:363)
at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1257)
at net.sf.hibernate.cfg.Configuration.add(Configuration.java:252)
at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:
288)
at org.springframework.orm.hibernate.LocalSessionFactoryBean.afterProper
tiesSet(LocalSessionFactoryBean.java:383)
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:990)
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.createBean(AbstractAutowireCapableBeanFactory.java:275)
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.createBean(AbstractAutowireCapableBeanFactory.java:193)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean
(AbstractBeanFactory.java:240)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean
(AbstractBeanFactory.java:163)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.
preInstantiateSingletons(DefaultListableBeanFactory.java:230)
at org.springframework.context.support.AbstractApplicationContext.refres
h(AbstractApplicationContext.java:304)
at org.springframework.web.context.support.XmlWebApplicationContext.refr
esh(XmlWebApplicationContext.java:131)
at org.springframework.web.context.ContextLoader.createWebApplicationCon
text(ContextLoader.java:167)
at org.springframework.web.context.ContextLoader.initWebApplicationConte
xt(ContextLoader.java:101)
at org.springframework.web.context.ContextLoaderListener.contextInitiali
zed(ContextLoaderListener.java:48)
at com.newsy.common.webapp.listener.StartupListener.contextInitialized(S
tartupListener.java:38)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContex
t.java:3827)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4
343)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase
.java:823)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:80
7)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:595)

at org.apache.catalina.core.StandardHostDeployer.addChild(StandardHostDe
ployer.java:903)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:494)
at org.apache.commons.beanutils.MethodUtils.invokeMethod(MethodUtils.jav
a:216)
at org.apache.commons.digester.SetNextRule.end(SetNextRule.java:256)
at org.apache.commons.digester.Rule.end(Rule.java:276)
at org.apache.commons.digester.Digester.endElement(Digester.java:1058)
at org.apache.catalina.util.CatalinaDigester.endElement(CatalinaDigester
.java:76)
at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source
)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement(
Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContent
Dispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Un
known Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.commons.digester.Digester.parse(Digester.java:1567)
at org.apache.catalina.core.StandardHostDeployer.install(StandardHostDep
loyer.java:488)
at org.apache.catalina.core.StandardHost.install(StandardHost.java:863)
at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.j
ava:483)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:427
)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:983)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java
:349)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(Lifecycl
eSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1091)

at org.apache.catalina.core.StandardHost.start(StandardHost.java:789)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1083)

at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:478
)
at org.apache.catalina.core.StandardService.start(StandardService.java:4
80)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:231
3)
at org.apache.catalina.startup.Catalina.start(Catalina.java:556)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:494)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:287)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:425)
11469 ERROR [main] context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean wit
h name 'sessionFactory' defined in ServletContext resource [/WEB-INF/conf/applic
ationContext-hibernate.xml]: Initialization of bean failed; nested exception is
net.sf.hibernate.MappingException: duplicate import: Channel
net.sf.hibernate.MappingException: duplicate import: Channel
at net.sf.hibernate.cfg.Mappings.addImport(Mappings.java:85)
at net.sf.hibernate.cfg.Binder.bindClass(Binder.java:127)
at net.sf.hibernate.cfg.Binder.bindSubclass(Binder.java:162)
at net.sf.hibernate.cfg.Binder.handleSubclass(Binder.java:1095)
at net.sf.hibernate.cfg.Binder.propertiesFromXML(Binder.java:1056)
at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:363)
at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1257)
at net.sf.hibernate.cfg.Configuration.add(Configuration.java:252)
at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:
288)
at org.springframework.orm.hibernate.LocalSessionFactoryBean.afterProper
tiesSet(LocalSessionFactoryBean.java:383)
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:990)
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.createBean(AbstractAutowireCapableBeanFactory.java:275)
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.createBean(AbstractAutowireCapableBeanFactory.java:193)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean
(AbstractBeanFactory.java:240)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean
(AbstractBeanFactory.java:163)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.
preInstantiateSingletons(DefaultListableBeanFactory.java:230)
at org.springframework.context.support.AbstractApplicationContext.refres
h(AbstractApplicationContext.java:304)
at org.springframework.web.context.support.XmlWebApplicationContext.refr
esh(XmlWebApplicationContext.java:131)
at org.springframework.web.context.ContextLoader.createWebApplicationCon
text(ContextLoader.java:167)
at org.springframework.web.context.ContextLoader.initWebApplicationConte
xt(ContextLoader.java:101)
at org.springframework.web.context.ContextLoaderListener.contextInitiali
zed(ContextLoaderListener.java:48)
at com.newsy.common.webapp.listener.StartupListener.contextInitialized(S
tartupListener.java:38)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContex
t.java:3827)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4
343)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase
.java:823)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:80
7)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:595)

at org.apache.catalina.core.StandardHostDeployer.addChild(StandardHostDe
ployer.java:903)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:494)
at org.apache.commons.beanutils.MethodUtils.invokeMethod(MethodUtils.jav
a:216)
at org.apache.commons.digester.SetNextRule.end(SetNextRule.java:256)
at org.apache.commons.digester.Rule.end(Rule.java:276)
at org.apache.commons.digester.Digester.endElement(Digester.java:1058)
at org.apache.catalina.util.CatalinaDigester.endElement(CatalinaDigester
.java:76)
at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source
)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement(
Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContent
Dispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Un
known Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.commons.digester.Digester.parse(Digester.java:1567)
at org.apache.catalina.core.StandardHostDeployer.install(StandardHostDep
loyer.java:488)
at org.apache.catalina.core.StandardHost.install(StandardHost.java:863)
at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.j
ava:483)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:427
)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:983)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java
:349)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(Lifecycl
eSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1091)

at org.apache.catalina.core.StandardHost.start(StandardHost.java:789)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1083)

at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:478
)
at org.apache.catalina.core.StandardService.start(StandardService.java:4
80)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:231
3)
at org.apache.catalina.startup.Catalina.start(Catalina.java:556)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:494)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:287)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:425)

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

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.