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?