-->
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: Trying to figure out single table per sub class mapping.
PostPosted: Sun Jun 12, 2005 12:38 am 
Newbie

Joined: Mon May 31, 2004 5:20 pm
Posts: 6
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.0

Mapping documents:
<class name="com.barrowsdevelopment.project_management.model.Project"
table="Projects" lazy="false">
<id name="oid" column="oid" unsaved-value="null">
<generator class="native"/>
</id>
<version name="version" unsaved-value="null" type="long"/>
<property name="active" column="active"/>

<any name="artifacts"
meta-type="com.barrowsdevelopment.project_management.model.Artifact"
id-type="java.lang.Long"
>
<column name="oid"/>
<column name="version"/>
<column name="description"/>
<column name="name"/>
</any>

<!--bag name="artifacts" lazy="false" inverse="false" cascade="all">
<key column="projectOid"/>
<one-to-many class="com.barrowsdevelopment.project_management.model.Artifact"/>
</bag-->
<property name="summary"/>
<property name="name"/>
</class>
<class name="com.barrowsdevelopment.project_management.model.UseCaseModel"
table="UseCaseModels" lazy="false">
<id name="oid" column="oid" unsaved-value="null">
<generator class="native"/>
</id>
<version name="version" unsaved-value="null" type="long"/>
<property name="active" column="active"/>
<bag name="useCases" lazy="false" inverse="false" cascade="all">
<key column="useCaseModelOid"/>
<one-to-many
class="com.barrowsdevelopment.project_management.model.UseCase"/>
</bag>
<bag name="actors" lazy="false" inverse="false" cascade="all">
<key column="useCaseModelOid"/>
<one-to-many
class="com.barrowsdevelopment.project_management.model.Actor"/>
</bag>
</class>
Code between sessionFactory.openSession() and session.close():
I use spring.
Full stack trace of any exception that occurs:
com.barrowsdevelopment.test.AbstractSpringTestCase.setUp()
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in URL [file:/home/grim/workspace/ProjectManagementCore/bin/test/dao/hibernate/BaseHibernateTestCase.xml]: Initialization of bean failed; nested exception is org.hibernate.MappingException: property mapping has wrong number of columns: com.barrowsdevelopment.project_management.model.Project.artifacts type: object
org.hibernate.MappingException: property mapping has wrong number of columns: com.barrowsdevelopment.project_management.model.Project.artifacts type: object
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:309)
at org.hibernate.mapping.RootClass.validate(RootClass.java:186)
at org.hibernate.cfg.Configuration.validate(Configuration.java:814)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1037)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:746)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:673)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:962)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:354)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:147)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:271)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:312)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:111)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
at com.barrowsdevelopment.test.AbstractSpringTestCase.getApplicationContext(AbstractSpringTestCase.java:271)
at com.barrowsdevelopment.test.AbstractSpringTestCase.setUp(AbstractSpringTestCase.java:93)
at junit.framework.TestCase.runBare(TestCase.java:125)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:474)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:342)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:194)
Name and version of the database you are using:

mysql
The generated SQL (show_sql=true):
Not having trouble getting to the database.
Debug level Hibernate log excerpt:
I"m trying to figure out how to use the base class Artifact, as the type for an array. Artifact itself will never be implemented, but it has quite few sublcasses. This seems like the perfect fit for table per concrete class mapping.
The problem is that I can't figure out how to get the many to one mapping to work. The documentation mentions an <any tag, shows an example, but doesn't really explain well how to get to the next step.
What is the next step? How do I map the one class to the many subclasses of Artifact?

_________________
Grim Shieldsson


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 12, 2005 4:44 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you have an <any> mapping. such a thing need two columns - one for the id and one for the discriminator.

_________________
Max
Don't forget to rate


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.