Hi,
I am working with hibernate for the first time and am just trying to get a first test application working to see how it works. I have used middlegen to create mapping files from the database schema, and changed them only slightly to add joined-class inheritence to two classes, although it seems that even when I use the files generated driectly by middlegen I have this problem. I then used hbm2java to generate java files but the followiong exception is thrown every time I try to buildSessionFactory. I am using mysql 4.1.2 and hibernate 2.1. The Class the exception refers to differs depending on what order I add classes to the configuration. Thank you in advance to anyone who can offer any help.
Joel
Exception:
net.sf.hibernate.MappingException: property mapping has wrong number of columns: com.foothills.fais.hibernate.StudentCategory.mark type: object
at net.sf.hibernate.mapping.PersistentClass.validate(PersistentClass.java:269)
at net.sf.hibernate.mapping.RootClass.validate(RootClass.java:199)
at net.sf.hibernate.cfg.Configuration.validate(Configuration.java:605)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:762)
at main.Test.main(Test.java:52)
Code:
Configuration cfg = new Configuration()
.addClass(com.foothills.fais.hibernate.Person.class)
.addClass(com.foothills.fais.hibernate.Mark.class)
.addClass(com.foothills.fais.hibernate.Address.class)
.addClass(com.foothills.fais.hibernate.EmailAddress.class)
.addClass(com.foothills.fais.hibernate.PhoneNumber.class)
.addClass(com.foothills.fais.hibernate.Track.class)
.addClass(com.foothills.fais.hibernate.Class.class)
.addClass(com.foothills.fais.hibernate.AssignmentDescription.class)
.addClass(com.foothills.fais.hibernate.Course.class)
.addClass(com.foothills.fais.hibernate.Term.class)
.addClass(com.foothills.fais.hibernate.EnrolledStudent.class)
.addClass(com.foothills.fais.hibernate.StudentCategory.class)
.addClass(com.foothills.fais.hibernate.TermWeight.class)
.addClass(com.foothills.fais.hibernate.CategoryDescription.class)
.addClass(com.foothills.fais.hibernate.CategoryWeight.class);
StuentCategory.hbm.xml:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin
http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->
<class
name="com.foothills.fais.hibernate.StudentCategory"
table="student_categories"
>
<meta attribute="class-description" inherit="false">
@hibernate.class
table="student_categories"
</meta>
<id
name="studentCategoryId"
type="java.lang.Object"
column="Student_Category_Id"
>
<meta attribute="field-description">
@hibernate.id
generator-class="native"
type="java.lang.Object"
column="Student_Category_Id"
</meta>
<generator class="native" />
</id>
<property
name="mark"
type="java.lang.Float"
column="mark"
length="12"
>
<meta attribute="field-description">
@hibernate.property
column="mark"
length="12"
</meta>
</property>
<property
name="comments"
type="java.lang.String"
column="comments"
length="65535"
>
<meta attribute="field-description">
@hibernate.property
column="comments"
length="65535"
</meta>
</property>
<!-- associations -->
<!-- bi-directional many-to-one association to Term -->
<many-to-one
name="term"
class="com.foothills.fais.hibernate.Term"
not-null="true"
>
<meta attribute="field-description">
@hibernate.many-to-one
not-null="true"
@hibernate.column name="term_id"
</meta>
<column name="term_id" />
</many-to-one>
<!-- bi-directional many-to-one association to CategoryDescription -->
<many-to-one
name="categoryDescription"
class="com.foothills.fais.hibernate.CategoryDescription"
not-null="true"
>
<meta attribute="field-description">
@hibernate.many-to-one
not-null="true"
@hibernate.column name="category_id"
</meta>
<column name="category_id" />
</many-to-one>
<!-- bi-directional many-to-one association to Student -->
<many-to-one
name="student"
class="com.foothills.fais.hibernate.Student"
not-null="true"
>
<meta attribute="field-description">
@hibernate.many-to-one
not-null="true"
@hibernate.column name="student_id"
</meta>
<column name="student_id" />
</many-to-one>
<!-- bi-directional many-to-one association to Class -->
<many-to-one
name="clazz"
class="com.foothills.fais.hibernate.Class"
not-null="true"
>
<meta attribute="field-description">
@hibernate.many-to-one
not-null="true"
@hibernate.column name="class_id"
</meta>
<column name="class_id" />
</many-to-one>
</class>
</hibernate-mapping>
Table Student_Categories:
CREATE TABLE IF NOT EXISTS Student_Categories(
Student_Category_Id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
student_id INT UNSIGNED NOT NULL,
class_id SMALLINT UNSIGNED NOT NULL,
category_id SMALLINT UNSIGNED NOT NULL,
term_id SMALLINT UNSIGNED,
mark FLOAT UNSIGNED,
comments TEXT,
INDEX student_index (student_id),
INDEX class_index (class_id),
INDEX category_index (category_id),
INDEX term_index (term_id),
FOREIGN KEY student_reference (student_id) REFERENCES Students(student_id) ON DELETE CASCADE,
FOREIGN KEY class_reference (class_id) REFERENCES Classes(class_id) ON DELETE CASCADE,
FOREIGN KEY category_reference (category_id) REFERENCES Category_Descriptions(category_id) ON DELETE CASCADE,
FOREIGN KEY term_reference (term_id) REFERENCES Terms(term_id) ON DELETE CASCADE
) ENGINE = INNODB;