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.  [ 4 posts ] 
Author Message
 Post subject: How to use a typedef ?
PostPosted: Fri Jul 30, 2010 2:38 am 
Pro
Pro

Joined: Mon Apr 16, 2007 8:10 am
Posts: 246
Hello,

I have defined a typedef for joda date time and now wonder how to use it.

Here is the definition:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
   <typedef name="jodaDateTime" class="org.joda.time.contrib.hibernate.PersistentDateTime" />
</hibernate-mapping>


But when I try using
Code:
        <property name="contactDateTime" type="jodaDateTime">
            <column name="contact_datetime" not-null="true" />
        </property>


instead of
Code:
        <property name="contactDateTime" type="org.joda.time.contrib.hibernate.PersistentDateTime">
            <column name="contact_datetime" not-null="true" />
        </property>


I get the following exception:
Quote:
Caused by: org.hibernate.MappingException: Could not determine type for: jodaDateTime, at table: contact, for columns: [org.hibernate.mapping.Column(contact_datetime)]
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:269)
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:440)
at org.hibernate.mapping.RootClass.validate(RootClass.java:192)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1121)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1306)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:814)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:732)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
... 37 more


Any clue ?


Top
 Profile  
 
 Post subject: Re: How to use a typedef ?
PostPosted: Fri Jul 30, 2010 3:01 am 
Pro
Pro

Joined: Mon Apr 16, 2007 8:10 am
Posts: 246
I wonder if this could be explained by the typedef.hbm.xml type definition file being parsed AFTER the other xml mapping files making use of the type.

All of these xml files, the typedef.hbm.xml file included, sit in the same directory.

Is there any way to make sure the typedef.hbm.xml file is being parsed before any mapping hbm.xml file ?


Top
 Profile  
 
 Post subject: Re: How to use a typedef ?
PostPosted: Wed Nov 24, 2010 6:52 pm 
Pro
Pro

Joined: Mon Apr 16, 2007 8:10 am
Posts: 246
Any one ?


Top
 Profile  
 
 Post subject: Re: How to use a typedef ?
PostPosted: Thu Nov 25, 2010 9:35 am 
Pro
Pro

Joined: Mon Apr 16, 2007 8:10 am
Posts: 246
To see if the typedef.hbm.xml file was being used, I replaced an argument with a dummy name, like:

Code:
   <typedef dummy="dateTime" class="org.joda.time.contrib.hibernate.PersistentDateTime" />


And I would get an exception for it at build time, leading me to think the file was parsed and therefore attempted to be used.

But when having it with the correct name argument I still get the original exception relating to the type dateTime not being known in:

Code:
      <property name="contactDateTime"
         type="dateTime">
         <column name="contact_datetime" />
      </property>


After Googling a bit I finally found the solution.

I needed to explicitly include the file in the Hibernate configuration, as in:

Code:
      <property name="mappingResources">
         <list>
            <value>com/thalasoft/learnintouch/core/domain/typedef.hbm.xml</value>
         </list>
      </property>


And now, I can use the type dateTime in the Hibernate mapping files.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.