Hibernate version:
2.1.6
Mapping documents:
<hibernate-mapping package="foo.bar">
<class name="foo.bar.TestClass" table="TEST_TABLE">
<id name="id" type="big_decimal" column="ID">
<generator class="native"/>
</id>
<!-- The important part where we map the column -->
<property name="myprop" column="VALUE" type="foo.bar.UDTType">
<meta attribute="property-type">foo.bar.MyUDT</meta>
</property>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
N/A
Full stack trace of any exception that occurs:
net.sf.hibernate.MappingException: property mapping has wrong number of columns: foo.bar.TestCass.data type: foo.bar.UDTType
at net.sf.hibernate.mapping.PersistentClass.validate(PersistentClass.java:269)
...
Name and version of the database you are using:
Oracle 9i
The generated SQL (show_sql=true):+
N/A
Debug level Hibernate log excerpt:
<Date> INFO Environment:469 - Hibernate 2.1.6
<Date> INFO Environment:498 - hibernate.properties not found
<Date> INFO Environment:529 - using CGLIB reflection optimizer
<Date> INFO Configuration:169 - Mapping file: ...\TestClass.hbm.xml
<Date> INFO Binder:229 - Mapping class: foo.bar.TestClass -> TEST_TABLE
<Date> INFO Configuration:627 - processing one-to-many association mappings
<Date> INFO Configuration:636 - processing one-to-one association property references
<Date> INFO Configuration:661 - processing foreign key constraints
Hello,
I am having trouble using Hibernate to persist objects against Oracle user defined types.
I am conducting a proof-of-concept for using Hibernate, for which I created a table that
uses a type we commonly use in our actual database. Let's say, for now that the type is
defined in oracle as follows:
TYPE MYTYPE AS OBJECT
(FIRST_FLAG CHAR(1)
,SECOND_FLAG CHAR(2)
,FIRST_STRING VARCHAR2(512)
,SECOND_STRING VARCHAR2(512)
)
I also created the hbm.xml file for the mapping of the TestClass mapped to this table. The mapping looks something like the one above:
Finally, I created three java classes: foo.bar.TestClass as the persistent entity,
foo.bar.MyUDT as the java value object implementation of the Oracle user type MYTYPE
(let's say the name of the property of this type in TestClass is called "data"),
and foo.bar.UDTType as the persister for instances of MyUDT. The latter has a class
definition that looks something like this:
-------------
package foo.bar;
...
public class UDTType implements UserType{
final static String UD_TYPE_NAME = "MYTYPE";
/*
This array is built to reflect the types
of fields composing the Oracle UDT. Is this
correct?
*/
private final static int[] TYPES = {
Types.CHAR,
Types.CHAR,
Types.VARCHAR,
Types.VARCHAR
};
...
public int[] sqlTypes(){ return TYPES;}
public Class returnedClass(){ return MyUDT.class;}
...
public Object nullSafeGet(ResultSet rs, String[] names, Object owner)
throws ...{
MyUDT obj = new MyUDT();
try{
ObjectInputStream ois = new ObjectInputStream(rs.getBinaryStream(names[1]));
obj.setFirstFlag();
obj.setSecondFlag();
obj.setFirstString();
obj.setSecondString();
}catch(IOExeption ioe){
...
}
return obj;
}
public Object nullSafeSet(PreparedStatement st, Object value, int index)
throws ...{
...
}
}
------------------------
The problem is when I try to open Hibern8Ide or with this configuration, or when I try
to use a JUnit that runs test methods to exercise persisting my class. I get the
following:
net.sf.hibernate.MappingException: property mapping has wrong number of columns: foo.bar.TestCass.data type: foo.bar.UDTType
at net.sf.hibernate.mapping.PersistentClass.validate(PersistentClass.java:269)
...
Any ideas?
|