[hibernate-issues] [Hibernate-JIRA] Closed: (HHH-1016) Defining joined-subclass in separate mapping file requires abstract parent to have a discriminator-value

Steve Ebersole (JIRA) noreply at atlassian.com
Mon Mar 21 13:00:45 EDT 2011


     [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1016?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Steve Ebersole closed HHH-1016.
-------------------------------


Closing stale resolved issues

> Defining joined-subclass in separate mapping file requires abstract parent to have a discriminator-value
> --------------------------------------------------------------------------------------------------------
>
>                 Key: HHH-1016
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1016
>             Project: Hibernate Core
>          Issue Type: Bug
>    Affects Versions: 3.0 final
>         Environment: Hibernate 3.0, MySQL 4.0.23-nt, Spring 1.2.3
>            Reporter: Josh Landin
>            Priority: Minor
>
> The documentation section 6.1.15 states that "It is possible to define subclass, union-subclass, and joined-subclass mappings in separate mapping documents, directly beneath hibernate-mapping".
> When including a joined-subclass within the class element that it extends, a discriminator-value is not required for the abstract parent class. However, when the joined-subclass is moved into its own mapping file, the parent class element's default discriminator-value (classname) is used and consequently fails the cast to a non-string.
> File Parent.hbm.xml:
> <hibernate-mapping>
>   <class name="com.foo.AbstractParent" table="parent" abstract="true" lazy="false">
>     <id name="id" type="java.lang.Long" column="entityId" unsaved-value="null"><generator class="native" /></id>
>     <discriminator column="type" type="java.lang.Integer" not-null="true"/>
>     <property name="name" type="java.lang.String" column="name" not-null="true" unique="true" length="100"/>
>   </class>
> </hibernate-mapping>
> File Child.hbm.xml:
> <hibernate-mapping>
>     <joined-subclass name="com.foo.Child" extends="com.foo.AbstractParent" table="child">
>       <key column="childId"/>
>       <property name="status"/>
>     </joined-subclass>
> </hibernate-mapping>
> File appctx_SessionFactory.xml (Spring):
> <beans>
>   <alias alias="sessionFactory" name="org.hibernate.SessionFactory"/>
>   <bean id="org.hibernate.SessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
>     <property name="mappingResources">
>       <list>
>         <value>/com/foo/Parent.hbm.xml</value>
>         <value>/com/foo/Child.hbm.xml</value>
>       </list>
>     </property>
>     <property name="hibernateProperties">
>       <props>
>         <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
>         <prop key="hibernate.show_sql">true</prop>
>         <prop key="hibernate.cglib.use_reflection_optimizer">false</prop>
>         <prop key="hibernate.jdbc.batch_size">0</prop>
>       </props>
>     </property>
>     <property name="dataSource">
>       <ref bean="javax.sql.DataSource"/>
>     </property>
>   </bean>
> </beans>
> Causes the following when loading the mappings upon retrieving the sessionFactory from the Spring context:
> Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.hibernate.SessionFactory' defined in file [C:\dev\foo\classes\com\foo\common\app\resources\appctx_SessionFactory.xml]: Initialization of bean failed; nested exception is org.hibernate.MappingException: Could not format discriminator value to SQL string
>   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:355)
>   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:226)
>   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:147)
>   at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:269)
>   at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:317)
>   at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:80)
>   at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:65)
>   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
>   at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
>   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
>   at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
>   at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:100)
>   ... 29 more
> Caused by: org.hibernate.MappingException: Could not format discriminator value to SQL string
>   at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:273)
>   at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
>   at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:211)
>   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1005)
>   at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:767)
>   at org.springframework.orm.hibernate3.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:693)
>   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1003)
>   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:348)
>   ... 40 more
> Caused by: java.lang.NumberFormatException: For input string: "com.foo.AbstractParent"
>   at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
>   at java.lang.Integer.parseInt(Integer.java:468)
>   at java.lang.Integer.<init>(Integer.java:609)
>   at org.hibernate.type.IntegerType.stringToObject(IntegerType.java:53)
>   at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:266)
>   ... 47 more
> )
> It seems like having (1) The parent class itself defined as abstract, and (2) The parent class mapping defined as abstract, would cause the discriminator-value to be unused.
> --
> Josh

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list