-->
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.  [ 2 posts ] 
Author Message
 Post subject: Issue while using SecondaryTable mapping
PostPosted: Tue Dec 18, 2007 3:30 am 
Newbie

Joined: Tue Dec 18, 2007 3:08 am
Posts: 2
I have an issue where I want to map an entity to two tables. I have an entity 'InventoryItem' corresponding to its table in db 'inventory_item'. I have an another entity 'InventoryReport' corresponding to table 'inventory_report' in db. InventoryReport has a FK relationship with InventoryItem. I want to use few columns of InventoryItem in InventoryReport and hence InventoryReport is required to mapped to two tables.
Now I have used annotation mapping @SecondaryTable in InventoryRpeort entity which is as follows:

[b]@Entity
@Immutable
@SecondaryTables({ @SecondaryTable(name="inventory_item", pkJoinColumns={@PrimaryKeyJoinColumn(name="id", referencedColumnName="id")})})
public class InventoryReportMatView
{
@Id
private Long id;
................
private String inventoryReportProperty;


@Column( name="inventory_Item_Property", table="inventory_item")
private String inventoryItemProperty;

}
[/b]

But with this I am getting Mapping Exception stating [b]"Same
physical table name reference several logical table names"[/b]

[b]Any kind of help is appreciated. Thanks in advance[/b]


Following is the stack trace:
[i]
Invocation of init method failed; nested exception is org.hibernate.MappingException: Same physical table name reference
several logical table names: inventory_item => 'InventoryItem' and 'inventory_item':org.hibernate.MappingException: Same
physical table name reference several logical table names: inventory_item => 'InventoryItem' and 'inventory_item' at
org.hibernate.cfg.Mappings.addTableBinding(Mappings.java:435)at
org.hibernate.cfg.annotations.TableBinder.fillTable(TableBinder.java: 159) at
org.hibernate.cfg.annotations.EntityBinder.addJoin(EntityBinder.java: 611) at
org.hibernate.cfg.annotations.EntityBinder.firstLevelSecondaryTablesB inding(EntityBinder.java:559) at
org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:58 2) at
org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(Anno tationConfiguration.java:498) at
org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(Annotatio nConfiguration.java:277) at
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.jav a:1286) at
org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(Annotat ionConfiguration.java:915) at
org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSession Factory(LocalSessionFactoryBean.java:798) at
org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessi onFactory(LocalSessionFactoryBean.java:738) at
org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPr opertiesSet(AbstractSessionFactoryBean.java:131)
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1057) at
org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.initializeBean(AbstractAutowireCapableBeanFactory.java:1024) at
org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.createBean(AbstractAutowireCapableBeanFactory.java:421) at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getOb ject(AbstractBeanFactory.java:245) at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistr
y.getSingleton(DefaultSingletonBeanRegistry.java:140) at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java:242) at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java:156) at
org.springframework.beans.factory.support.BeanDefinitionValueResolver
.resolveReference(BeanDefinitionValueResolver.java:248) at
org.springframework.beans.factory.support.BeanDefinitionValueResolver
.resolveValueIfNecessary(BeanDefinitionValueResolver.java:128) at
org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:950) at
org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.populateBean(AbstractAutowireCapableBeanFactory.java:740) at
org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.createBean(AbstractAutowireCapableBeanFactory.java:417) at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getOb ject(AbstractBeanFactory.java:245) at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistr
y.getSingleton(DefaultSingletonBeanRegistry.java:140) at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java:242) at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java:156) at
org.springframework.beans.factory.support.BeanDefinitionValueResolver
.resolveReference(BeanDefinitionValueResolver.java:248) at
org.springframework.beans.factory.support.BeanDefinitionValueResolver
.resolveValueIfNecessary(BeanDefinitionValueResolver.java:128) at
org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:950) at
org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.populateBean(AbstractAutowireCapableBeanFactory.java:740) at
org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.createBean(AbstractAutowireCapableBeanFactory.java:417) at
org.springframework.beans.factory.support.BeanDefinitionValueResolver
.resolveInnerBeanDefinition(BeanDefinitionValueResolver.java:200) at
org.springframework.beans.factory.support.BeanDefinitionValueResolver
.resolveValueIfNecessary(BeanDefinitionValueResolver.java:116) at
org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:950) at
org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.populateBean(AbstractAutowireCapableBeanFactory.java:740) at
org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.createBean(AbstractAutowireCapableBeanFactory.java:417) at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getOb ject(AbstractBeanFactory.java:245) at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistr
y.getSingleton(DefaultSingletonBeanRegistry.java:140) at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java:242) at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java:156) at
org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyC
reator.findCandidateAdvisors(AbstractAdvisorAutoProxyCreator.java:100) at
org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyC
reator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:73) at
org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyC
reator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:57) at
org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.
postProcessAfterInitialization(AbstractAutoProxyCreator.java:255) at
org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFa ctory.java:312) at
org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.initializeBean(AbstractAutowireCapableBeanFactory.java:1033) at
org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.createBean(AbstractAutowireCapableBeanFactory.java:421) at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getOb ject(AbstractBeanFactory.java:245) at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistr
y.getSingleton(DefaultSingletonBeanRegistry.java:140) at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java:242) at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java:156) at
org.springframework.beans.factory.support.DefaultListableBeanFactory.
preInstantiateSingletons(DefaultListableBeanFactory.java:270) at
org.springframework.context.support.AbstractApplicationContext.refres h(AbstractApplicationContext.java:346) at
org.springframework.web.context.support.AbstractRefreshableWebApplica
tionContext.refresh(AbstractRefreshableWebApplicationContext.java:156) at
org.springframework.web.context.ContextLoader.createWebApplicationCon text(ContextLoader.java:246) at
org.springframework.web.context.ContextLoader.initWebApplicationConte xt(ContextLoader.java:184) at
org.springframework.web.context.ContextLoaderListener.contextInitiali zed(ContextLoaderListener.java:49) at
org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler. java:511) at
org.mortbay.jetty.servlet.Context.startContext(Context.java:135) at
org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.jav a:1191) at
org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java: 481) at
org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:434 ) at
org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java: 40) at
org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection .java:147) at
org.mortbay.jetty.handler.ContextHandlerCollection.doStart(ContextHan dlerCollection.java:120) at
org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java: 40) at
org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection .java:147) at
org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java: 40) at
org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java: 117) at
org.mortbay.jetty.Server.doStart(Server.java:210) at
org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java: 40) at
org.mortbay.jetty.plugin.Jetty6PluginServer.start(Jetty6PluginServer. java:134) at
org.mortbay.jetty.plugin.AbstractJettyMojo.startJetty(AbstractJettyMo jo.java:332) at
org.mortbay.jetty.plugin.AbstractJettyMojo.execute(AbstractJettyMojo. java:277) at
org.mortbay.jetty.plugin.AbstractJettyRunMojo.execute(AbstractJettyRu nMojo.java:195) at
org.mortbay.jetty.plugin.Jetty6RunMojo.execute(Jetty6RunMojo.java:183 ) at
org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPlugi nManager.java:412) at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(Defa ultLifecycleExecutor.java:534) at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandalone Goal(DefaultLifecycleExecutor.java:488) at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(Defau ltLifecycleExecutor.java:458) at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHan dleFailures(DefaultLifecycleExecutor.java:306) at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegmen ts(DefaultLifecycleExecutor.java:273) at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLi fecycleExecutor.java:140) at
org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:322) at
org.apache.maven.DefaultMaven.execute(DefaultMaven.java:115) at org.apache.maven.cli.MavenCli.main(MavenCli.java:256) 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:585) at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255) at
org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
[/i]


Top
 Profile  
 
 Post subject: RE: Issue while using SecondaryTable mapping
PostPosted: Wed Dec 26, 2007 7:32 am 
Newbie

Joined: Tue Dec 18, 2007 3:08 am
Posts: 2
I could not fix the issue but got the above problem solved by using inheritance. I extended InventoryItem class to get a child class InventoryReport. InventoryReport thus had access to all fields of parent class and also declared few other fields in it. I mapped this class to a seaprate table and got a class referring to two tables.


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