-->
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.  [ 5 posts ] 
Author Message
 Post subject: Need to define Custom User Type for Multiple Databases
PostPosted: Wed Aug 24, 2005 4:05 pm 
Newbie

Joined: Mon Jul 18, 2005 7:45 pm
Posts: 15
Location: Argentina
This is my first post and I want to thanks Hibernate Team for a greate tool.
I'm learning now but I will try to contribute as much as I can, for the moment
I have a question to ask:

I´m dealing with legacy database and I have all columns defined as CHAR SQL datatype.
Reading this Forum I found that the best solution to the issue is defining a Custom Type, but I also have to support multiple Databases like Oracle and SQL Server.
Oracle has special dealing with CHAR types and I need to use OracleTypes.FIXED_CHAR for setting prepared statement properly, as I read from the wiki: http://www.hibernate.org/Documentation/ ... 2AndOracle
On SQL Server I can directly use Types.CHAR and PreparedStatement.setString
I need to find a way of doing this using the same Custom User Type.

Can I do this extending Oracle Dialect?

Any ideas will be appreciated.
Thank you in advance,

Daniel
Hibernate version: 3.0.5


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 24, 2005 5:22 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
I need help with this same exact problem. I've been trying to use that OracleCHAR but with no avail

I have my hbm file as follows
Code:
    <property
        name="servername"
        type="dars.apis.common.dao.hibernate.type.OracleCHAR"
        column="servername"
        length="10"
    >
        <meta attribute="property-type">java.lang.String</meta>
    </property>


I have some other similar UDTs on some attributes and primary keys, but only the ones on primary keys are ever called and used successfully.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 24, 2005 6:35 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
user oracle varchar2 type except char
varchar2 work like sql char type and mappint to string work fine


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 25, 2005 8:48 am 
Newbie

Joined: Mon Jul 18, 2005 7:45 pm
Posts: 15
Location: Argentina
Thank you for your answer.
I can´t use varchar2 because as I said this is legacy database already in production with other software I can't modify table definitions.

From now I resolved asking for the dialect at User Type method.

I did this:

Code:
   public void nullSafeSet(PreparedStatement st, Object value, int index)
         throws HibernateException, SQLException {
      String dialect=HibernateUtil.getDialectAlias();
      if(dialect!=null){
         if(dialect.equals("ORACLE")){
            st.setObject(index,(String)value,OracleTypes.FIXED_CHAR);
         }else{
            st.setString(index, (String) value);
            
         }
      }else{
         st.setString(index, (String) value);
      }
   }


it´s not very elegant but it works.

Daniel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 25, 2005 9:25 am 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
I can't use varchar2 either, I am stuck with a legacy database. I am still having a problem using a FIXED_CHAR type in the where clause of a select statement. It doesn't get padded(doesn't use the UDT type) when it is used in a where clause and always returns false so my queries return zero entries.


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