Hibernate version: 3.2CR2 with Annotations 3.2.0CR1
I am having trouble writing a CompositeUserType that has properties which are custom UserTypes as opposed to Hibernate defined types.
Here's the relevant snippet of my DateIntervalCompositeUserType...
Code:
private static final String[] PROPERTY_NAMES = { "start", "end" };
private static final Type[] PROPERTY_TYPES = {
Hibernate.custom(DateUserType.class),
Hibernate.custom(DateUserType.class)
};
and here's the relevant snippet of DateUserType
Code:
private static final int[] SQL_TYPES = new int[] { Types.DATE, };
public int[] sqlTypes() { return SQL_TYPES; }
public Class returnedClass() { return Date.class; }
Please note that Date is my own specialised class
NOT java.util.Date or java.sql.Date!
DateInterval is mapped as follows...
Code:
@Type(type="date_interval")
@Columns(columns = {
@Column(name="START"),
@Column(name="END")
})
private DateInterval effectivity;
...and typedefs are picked up from package-info.java as follows:
Code:
@TypeDefs( {
@TypeDef(
name="date",
typeClass=DateUserType.class),
@TypeDef(
name="date_interval",
typeClass=DateIntervalCompositeUserType.class),
} )
This leads to the following explosion:
Full stack trace of any exception that occurs:Code:
Caused by: org.hibernate.MappingException: Could not determine type for: date_interval, for columns: [org.hibernate.mapping.Column(START), org.hibernate.mapping.Column(END)]
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:266)
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:253)
at org.hibernate.mapping.Property.isValid(Property.java:185)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:395)
at org.hibernate.mapping.RootClass.validate(RootClass.java:192)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1021)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1206)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:871)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:797)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:877)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:846)
... 26 more
So the question is whether it is possible to have a CompositeUserType that is composed of custom UserTypes and, if so, what exactly am I doing wrong?