-->
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: Hibernate 3.2 (db SQLBase) : insert long varchar ?
PostPosted: Sun Dec 17, 2006 6:59 pm 
Newbie

Joined: Sun Dec 17, 2006 6:30 pm
Posts: 9
Hello,

I have a problem inserting long varchar... with Gupta SQLBase

I have a sample that works in a java SE application :

java.io.File file = new java.io.File("longs.txt");
long fileLength = file.length();
java.io.InputStream fin = new java.io.FileInputStream(file);
java.sql.PreparedStatement pstmt = con1.prepareStatement("INSERT INTO test VALUES (1,?)");
pstmt.setAsciiStream(1, fin,(int)fileLength);
pstmt.executeUpdate();

But with Hibernate 3.2.1.GA (JBoss 4.0.4), I have tried with some configurations but it doesn't work properly...
The config which is almost good is this one :

@Type(type="serializable")
private String slv_value;

But when the insert is executed, the string inserted is not good...
For example, when I try to insert :
"<Item>
<Cir00310_id>47372</Cir00310_id>
<TraMatric>0000000001</TraMatric>
<TraFct>01</TraFct>
<PeriodStart>20066</PeriodStart>
<PeriodEnd>20069</PeriodEnd>
</Item>"
And I try to read it again, it returns :
"’
<Cir00310_id>47376</Cir00310_id>
<TraMatric>0000000002</TraMatric>
<TraFct>01</TraFct>
<PeriodStart>20066</PeriodStart>
<PeriodEnd>20069</PeriodEnd>
</Item></Item>"

I have tried the type "text" but it doesn't work with the JDBC Driver of SQLBase...

So, how can I "take the control" of writing long varchar in Hibernate ???
How can I be sure that Hibernate uses the setAsciiStream() of the JDBC Driver ?
A method to override ?

Thanks,

Olivier


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 17, 2006 7:05 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
yes, use a custom UserType

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 18, 2006 6:51 pm 
Newbie

Joined: Sun Dec 17, 2006 6:30 pm
Posts: 9
Thanks Emmanuel !

I have created a custom UserType and it works !!!

Here is the code :

Code:
public class SQLBaseLongVarcharType implements UserType
{
   
    /** Creates a new instance of LongVarcharType */
    public SQLBaseLongVarcharType()
    {
    }
   
    public int[] sqlTypes()
    {
        return new int[] { Types.LONGVARCHAR };
    }

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

    public boolean equals(Object x, Object y)
        throws HibernateException
    {
        return (x == y) || (x != null && y != null && (x.equals(y)));
    }

    public Object nullSafeGet(ResultSet inResultSet, String[] names, Object o)
        throws HibernateException, SQLException
    {
        String val = (String)Hibernate.STRING.nullSafeGet(inResultSet, names[0]);
        return val;
    }

    public void nullSafeSet(PreparedStatement inPreparedStatement, Object o, int i)
        throws HibernateException, SQLException
    {
        String valStr = (String) o;
        java.io.InputStream val;
        try
        {
            val = new ByteArrayInputStream(valStr.getBytes("UTF-8"));
            inPreparedStatement.setAsciiStream(i, val, valStr.length());
        } catch (UnsupportedEncodingException ex)
        {
            ex.printStackTrace();
        }
    }

    public Object deepCopy(Object o) throws HibernateException
    {
        if (o==null) return null;
        return new String(((String) o));
    }

    public boolean isMutable()
    {
        return false;
    }

    /**
     * @see org.hibernate.usertype.UserType#assemble(java.io.Serializable, java.lang.Object)
     */
    public Object assemble(Serializable cached, Object owner)
    {
        return cached;
    }

    /**
     * @see org.hibernate.usertype.UserType#disassemble(java.lang.Object)
     */
    public Serializable disassemble(Object value)
    {
        return (Serializable) value;
    }

    /**
     * @see org.hibernate.usertype.UserType#replace(java.lang.Object, java.lang.Object, java.lang.Object)
     */
    public Object replace(Object original, Object target, Object owner)
    {
        return original;
    }

    /**
     * @see org.hibernate.usertype.UserType#hashCode(java.lang.Object)
     */
    public int hashCode(Object x)
    {
        return x.hashCode();
    }
   
}


Top
 Profile  
 
 Post subject: Re: Hibernate 3.2 (db SQLBase) : insert long varchar ?
PostPosted: Mon Nov 22, 2010 5:38 am 
Newbie

Joined: Mon Nov 22, 2010 5:26 am
Posts: 9
Beginner


Joined: Mon Jan 22, 2007 12:16 pm
Posts: 21 I have just started working with Hibernate. I would like to use it with SQLBase. I realize that I need to extend Dialect to get things to work, but I am not sure what I need to have in the new dialect class I create.

The only information I can find on the web, is that creating my own dialect is 'easy'. Are there any resources available on what I need to do?

Thanks for any help.

-Mark





Top

kochcp Post subject: Posted: Mon Jan 22, 2007 1:38 pm

Expert


Joined: Fri Aug 19, 2005 1:11 pm
Posts: 628
Location: Cincinnati you can check out what the other dialect classes look like in the source

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.




Top

fizzbananafrance Post subject: Posted: Tue Jan 30, 2007 8:45 am

Beginner


Joined: Mon Jan 22, 2007 12:16 pm
Posts: 21 In the end, it was very helpful to look at other dialect classes, but the most important thing was to read/understand the Dialect.java class.

thanks for the response.

-mark


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.