-->
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.  [ 1 post ] 
Author Message
 Post subject: Error n simple cstom type - why?
PostPosted: Wed Mar 05, 2008 11:53 pm 
Newbie

Joined: Tue Mar 04, 2008 12:12 am
Posts: 7
Location: Wellington, New Zealand
I'm getting this exception, and I dont understand WHY
Quote:
java.lang.ExceptionInInitializerError
Caused by: org.hibernate.MappingException: Could not determine type for: DAType, for columns: [org.hibernate.mapping.Column(DA)]


My usertype is very simple - it takes a class, and stores its .toString() to the database. the Constructor takes the string to re-build the object.

Can anone see where I've gone wrong?

My other usertypes work, so I cant see whats wrong with this one,

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>
   <class name="DATest" table="TEST">
       <id name="id" type="int" column="ID">
           <generator class="native"/>
       </id>
        <property name="da" type="DAType">
         <column name="DA"/>
      </property>
   </class>
</hibernate-mapping>


Code:
public class DAType implements UserType {

   public static final int[] SQL_TYPES ={Types.VARCHAR};

   public Object assemble(Serializable value, Object parent)
         throws HibernateException {
      return new DA((String)value);
   }


   public Serializable disassemble(Object value) throws HibernateException {
      DA da = (DigestAlgorithm)value;
      return da.toString();
   }
   
   public Object deepCopy(Object value) throws HibernateException {
      return value.toString();
   }

   public boolean equals(Object arg0, Object arg1) throws HibernateException {
      return arg0.equals(arg1);
   }

   public int hashCode(Object arg0) throws HibernateException {
      return arg0.hashCode();
   }

   public boolean isMutable() {
      return false;
   }

   public Object nullSafeGet(ResultSet results, String[] columnNames, Object Owner)
         throws HibernateException, SQLException {
      String value = results.getString(results.findColumn(columnNames[0]));
      return assemble(value, null);
   }

   public void nullSafeSet(PreparedStatement st, Object value, int index)
         throws HibernateException, SQLException {
      st.setString(index, (String)disassemble(value));
   }

   public Object replace(Object target, Object original, Object parent)
         throws HibernateException {
         target = original;
      return original;
   }

   public Class returnedClass() {
      return DA.class;
   }

   public int[] sqlTypes() {
      return SQL_TYPES;
   }

}


Code:
public class DA{
    int i;
    public DA(String num){
        j = Integer.getInteger(num);
        i = j.intValue();
    }


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.