-->
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 mapping the primitive to VARCHAR in the database
PostPosted: Fri Dec 24, 2004 4:29 am 
Newbie

Joined: Mon Dec 20, 2004 2:22 am
Posts: 3
Location: Taiwan
Code:

class User{
    String name;
    int age;
    ......
}



<hibernate-mapping>
    <class name="name"/>
    ......
<hibernate-mapping>




I need that the property age in the database is VARCHAR not INTEGER, what I can do in the mapping file...

best regards,

Stan


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 24, 2004 6:09 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Use a custom UserType - see the wiki for examples.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 24, 2004 6:52 am 
Newbie

Joined: Mon Dec 20, 2004 2:22 am
Posts: 3
Location: Taiwan
michael wrote:
Use a custom UserType - see the wiki for examples.



I've uesd the UserType, the my problem is that how cause the age is the premitive type...

my UserType is similar to this.
Code:
public class MyUserType implements UserType {

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

   public int[] sqlTypes() {
      // TODO Auto-generated method stub
      return SQL_TYPES;
   }

   public Class returnedClass() {
      // TODO Auto-generated method stub
      return int.class;
   }


   public Object nullSafeGet(ResultSet resultSet, String[] names, Object owner) throws HibernateException, SQLException {
      if(resultSet.wasNull())
         return null;
      String string = resultSet.getString(names[0]);
   
      return new Integer(string);
   }

   public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
      if(value == null){
         st.setNull(index, Types.VARCHAR);
      }else{
         Integer date = (Integer)value;
         st.setString(index, date.toString());
      }   
   }
   
   ......

}


The problem is the the nullSaftGet method can not get the correct resultSet...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 24, 2004 1:28 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
I don't get what your problem is ...


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.