-->
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: CompositeUserType containing UserTypes
PostPosted: Wed Jun 07, 2006 2:02 pm 
Newbie

Joined: Sun May 30, 2004 7:38 am
Posts: 7
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?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 07, 2006 5:53 pm 
Newbie

Joined: Sun May 30, 2004 7:38 am
Posts: 7
All fixed!!!

If you're using annotations with package-info.java for TypeDefs, make sure the TypeDef(s) are located in a package-info.java in the same package where the actual classes referred to by the TypeDefs live.

The annotations doc tends to imply that TypeDefs are global (in a session) which had suggested to my twisted mind that you can stuff all TypeDefs in a package-info at the top of a package hierarchy. You can't! No problem, I think it's much better that the TypeDefs live in the same package-info where the actual classes are.

Cheers.


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.