-->
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: Informix 7.31 vs. Hibernate
PostPosted: Thu Jun 09, 2005 5:37 am 
Newbie

Joined: Thu Jun 09, 2005 4:09 am
Posts: 3
Hi!

I'm currently having some trouble deploying a Hibernate-based application on top of Informix 7.31. First, as Hibernate seems to only ship a dialect for Informix 9.x and above out-of-the-box, I had to write my own Informix7Dialect in order to make things work:

Code:
package com.kesselheim.hibernatedemo;

import java.sql.Types;

import org.hibernate.MappingException;
import org.hibernate.dialect.InformixDialect;


public class Informix7Dialect extends InformixDialect {
   
    public InformixDialect(){
      super();
      registerColumnType(Types.BIGINT, "int");
      registerColumnType(Types.CLOB, "text");
      registerColumnType(Types.TIMESTAMP, "datetime year to second");
   }

   public String getIdentityColumnString() throws MappingException {
      return "serial not null";
   }
   
}


Using that dialect, I'm able to deploy my application (using hibernate) on Informix 7.31 (hibernate even generated the correct table structure on the fly).

Another problem comes into play when running on a (pre-defined) DB schema with discriminator columns beeing of type char(20), as Informix happens to always return a String of size 20 in its ResultSet, regardless how many (non-whitespace) characters were actually in there. My question therefore: Is it possible to adapt the dialect (or whatever class there is, perhaps by overloading StringType and making it the default mapping for java.lang.String?) so that all String values are trimmed before they're given back to my hibernate application?

Best regards,

Chris


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 09, 2005 7:32 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
http://www.hibernate.org/hib_docs/v3/re ... pes-custom


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 13, 2005 8:06 am 
Newbie

Joined: Thu Jun 09, 2005 4:09 am
Posts: 3
The following seems to work:

Code:
package eu.ohim.rec.rcd.integration.hibernate;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.hibernate.type.StringType;


public class TrimmedStringType extends StringType {
   
    /* (non-Javadoc)
     * @see org.hibernate.type.NullableType#get(java.sql.ResultSet, java.lang.String)
     */
    public Object get(ResultSet rs, String name) throws SQLException {
        String s = (String) super.get(rs, name);
        if (s != null)
            s = s.trim();
        return s;
    }
   
    /* (non-Javadoc)
     * @see org.exolab.castor.xml.schema.XMLType#getName()
     */
    public String getName() {
        return "trimmed_string";
    }

}


Unfortunately, this puts database specific details into my hibernate mapping files (as only informix seems to carry the problem of padding strings with spaces when using CHAR(*) columns as the discriminator).

Best regards,

Chris


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 14, 2005 1:58 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Not sure of the demand but if you have the time - submit the new dialect to JIRA for consideration so others can use it.


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.