-->
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: Problems with inheritance mapping
PostPosted: Mon Sep 17, 2007 9:24 am 
Newbie

Joined: Mon Jul 23, 2007 10:17 am
Posts: 12
Location: www.ultrasharpware.com
Hi!
I have two entities Project and FinishedProject. FinishedProject extends Project. Project has id and name. FinishedProject also has total_effort, iterations, total_loc. I'm ttying to map this association but I receive ecxeption when testing mappings and I can't figure out where is my fault.
Please help!
Thanks in advance!

SQL:
CREATE TABLE project(
id INT PRIMARY KEY AUTO_INCREMENT NOT NULL,
name VARCHAR(20) NOT NULL,

type VARCHAR(20) NOT NULL,
total_effort VARCHAR(30),
iterations INT CHECK (iterations > 0),
total_loc INT CHECK (total_loc > 0)
);

Hibernate version:
3.1.3
Mapping documents:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

    <class name="com.softserve.persistent.entities.Project" table="project">

        <id name="id" column="id" type="java.lang.Integer">
            <generator class="native"/>
        </id>

        <discriminator column="type" type="java.lang.String"/>

        <property name="name" type="java.lang.String"/>

        <set name="tasks" table="task" inverse="true" lazy="false">
            <key column="project_id" not-null="true"/>
            <one-to-many class="com.softserve.persistent.entities.Task"/>
        </set>


        <!--FinishedProject subclass mapping-->

        <subclass name="com.softserve.persistent.entities.FinishedProject" discriminator-value="FINISHED">

            <property name="totalEffort" column="total_effort" type="java.lang.String"/>
            <property name="iterations" column="iterations" type="java.lang.Integer"/>
            <property name="totalLoc" column="total_loc" type="java.lang.Integer"/>

            <set name="features" table="feature" lazy="false">
                <key column="project_id"/>
                <one-to-many class="com.softserve.persistent.entities.Feature"/>
            </set>
        </subclass>

    </class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Code:
     
   Map metadata = sessionFactory.getAllClassMetadata();


    @Test
    public void testEverything() throws Exception {

        for (Object obj : metadata.values()) {

            Session session = sessionFactory.openSession();
            String className = null;

            try {
                EntityPersister persister = (EntityPersister) obj;

                className = persister.getClassMetadata().getEntityName();
                List result = session.createQuery("from " + className + " c").list();

                System.out.println("testing " + className);

                for (Object o : result) {
                    System.out.println("    " + o);
                }
            } catch (Exception ex) {
                fail("Hibernate mapping error. Following class has incorrect mapping: " + className);
            } finally {
                session.close();
            }
        }
    }

Full stack trace of any exception that occurs:
junit.framework.AssertionFailedError: Hibernate mapping error. Following class has incorrect mapping: com.softserve.persistent.entities.Project
at junit.framework.Assert.fail(Assert.java:47)
at tests.helpers.HibernateMapTest.testEverything(HibernateMapTest.java:64)

_________________
kodlan
http://www.UltraSharpWare.com
http://www.UltraSharpWare.com/blog


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 17, 2007 1:37 pm 
Regular
Regular

Joined: Sun Sep 17, 2006 2:48 am
Posts: 81
Location: California
Did you see what ex says?


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.