Announcement Announcement Module
No announcement yet.
BeanCreationException with Hibernate subclass Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • BeanCreationException with Hibernate subclass

    I'm using Spring DAO with Hibernate. I defined an hbm map with a class and 3 subclasses in a standard way, with a hilo generator (the problem does not disappear if I use a native generator).
    Here is my hibernate map:
    <class name="Address" table="address" discriminator-value="Addr">
            <id name="addressid" column="addressid" type="java.lang.Long">
                <generator class="hilo"/>
     		<discriminator column="addresstype" />
            <property name="addresstype" column="addresstype" type="java.lang.String" insert="false" update="false" />
            <property name="countrytelcode" column="countrytelcode" type="java.lang.String" />
            <property name="nationaldirectdialingprefix" column="nationaldirectdialingprefix" type="java.lang.String" />
            <property name="areacode" column="areacode" type="java.lang.String" />
            <property name="number" column="number" type="java.lang.String" />
            <property name="extension" column="extension" type="java.lang.String" />
            <property name="physicaltype" column="physicaltype" type="java.lang.String" />
            <property name="webaddress" column="webaddress" type="java.lang.String" />
            <property name="email" column="email" type="java.lang.String" />
    	<subclass name="GeographicAddress" discriminator-value="Geo">
    		<property name="postbox" column="postbox" type="java.lang.String" />
            <property name="floor" column="floor" type="java.lang.String" />
            <property name="room" column="room" type="java.lang.String" />
            <property name="streetname" column="streetname" type="java.lang.String" />
            <property name="additionalstreername" column="additionalstreername" type="java.lang.String" />
            <property name="buildingname" column="buildingname" type="java.lang.String" />
            <property name="buildingnumber" column="buildingnumber" type="java.lang.String" />
            <property name="inhousemail" column="inhousemail" type="java.lang.String" />
            <property name="department" column="department" type="java.lang.String" />
            <property name="cityname" column="cityname" type="java.lang.String" />
            <property name="postalzone" column="postalzone" type="java.lang.String" />
            <property name="region" column="region" type="java.lang.String" />
            <property name="district" column="district" type="java.lang.String" />
            <property name="timezoneoffset" column="timezoneoffset" type="java.lang.String" />
            <property name="east" column="east" type="java.lang.Integer" />
            <property name="west" column="west" type="java.lang.Integer" />
            <property name="north" column="north" type="java.lang.Integer" />
            <property name="south" column="south" type="java.lang.Integer" />
    	<subclass name="EmailAddress" discriminator-value="Email">
    	        <property name="email" column="email" type="java.lang.String" />
    	<subclass name="WebAddress" discriminator-value="Web">
    	        <property name="webaddress" column="webaddress" type="java.lang.String" />
    I run a trivial unit test that uses the standard Spring sessionFactory. When the Spring bean factory starts I have this error message:
    org.springframework.beans.factory.BeanCreationException&#58; Error creating bean with name 'sessionFactory' defined in class path resource &#91;springconf.xml&#93;&#58; Initialization of bean failed; nested exception is org.hibernate.PropertyAccessException&#58; IllegalArgumentException occurred calling getter of
    What is surprising is that if I delete the last two subclasses (leaving only one subclass) everything works. Another way to avoid the problem is to use an "assigned" generator.

    So it seems to be a strange combination of number of subclasses + generator type.

    I did not find any mention of a "subclassing problem" in Hibernate Forums, so I'm wondering if it's a Spring problem. I'm new in Spring, so I need help to do a better diagnostic.

    My configuration:
    Java 5.0
    Spring 1.2.2
    Hibernate 3.0.5
    PostgreSQL 8.0


  • #2
    Sorry to all, it was my fault. I just mispelled the inheritance in the Java class definition.

    It's time to go to bed .