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)