-->
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.  [ 6 posts ] 
Author Message
 Post subject: Error saving Blob in Oracle9i with Hibernate 3.0.5 and Jboss
PostPosted: Wed Nov 16, 2005 7:33 am 
Newbie

Joined: Wed Nov 16, 2005 6:27 am
Posts: 2
Hi,

I'm using Oracle9i with Hibernate 3.0.5 and Jboss 3.2.4.

Here is my POJO :

public class ReportsDO{

private long id;
private java.sql.Blob report;

public long getId() { return id; }
public void setId(long id) { this.id = id; }

public java.sql.Blob getReport() {
return this.report;
}

public void setReport(java.sql.Blob report) {
this.report = report;
}
}

If I'm trying to write more then 4K in the BLOB type column, it isgiving me following errors......

================================================
2005-11-16 15:04:12,666 ERROR [org.hibernate.util.JDBCExceptionReporter:72] operation not allowed: streams type cannot be used in batching
2005-11-16 15:04:12,698 ERROR [org.hibernate.event.def.AbstractFlushingEventListener:277] Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: could not insert: [com.bupa.consult.dataaccess.dataobject.reports.ReportObjectsDO]
at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92)
================================================


I've already set StreamsForBinaryEnabled = true.
I tried the latest release of oracle 9.2.0.5 driver also but it did not work.
That's why I came to the conclusion that there is some problem with the driver. Then finally I replaced oracle 9i thin driver (9.2.0.5)
Quote:
(ojdbc14.jar)
with oracle 10g thin driver (10.1.0.2.0) in the jboss lib and It worked successfully.


can anybody help me on this with oracle 9i driver only. Is there any other solution to this.

Many Thanks

Manish


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 16, 2005 9:02 am 
Beginner
Beginner

Joined: Tue Jul 19, 2005 5:08 am
Posts: 26
Location: Germany
I had the same problem with the oracle 9i driver and found no solution with it (under websphere). The workaround was the same, now i´m using the oracle 10 g driver and it works fine. So, what is your problem, using the oracle 10 g driver for your application?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 23, 2005 12:14 am 
Newbie

Joined: Wed Nov 16, 2005 6:27 am
Posts: 2
In our environment other applications are also deployed on the Jboss and those are using oracle 9i driver. I'm not very sure , whether I can deply both the drivers on the same instance of the jboss. There may be a classloader problem with the jboss.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 06, 2005 8:36 am 
Beginner
Beginner

Joined: Tue Jul 19, 2005 5:08 am
Posts: 26
Location: Germany
but you could deploy the jdbc driver with your application and then set the classloader directive to load the libaries of your application before loading the libaries of the server.


greetings, arno


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 09, 2005 3:15 am 
Beginner
Beginner

Joined: Tue Jul 12, 2005 11:15 am
Posts: 29
----------------------------------------------------
you must implement your POJO like that

public class ReportsDO{

private long id;
private byte[] report;

public long getId() { return id; }
public void setId(long id) { this.id = id; }

public byte[] getReport() {
return this.report;
}

public void setReport(byte[] report) {
this.report = report;
}
}
----------------------------------------------------
in your ReportsDO.hbm.xml
replace your old property by:
<property name="report" type="BinaryBlobType" column="YOUR_REPORTCOLUMN"/>

----------------------------------------------------
add this class to your project:
import java.io.IOException;
import java.io.OutputStream;
import java.io.Serializable;
import java.sql.Blob;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;

import oracle.sql.BLOB;

import org.hibernate.Hibernate;
import org.hibernate.HibernateException;
import org.hibernate.usertype.UserType;

public class BinaryBlobType implements UserType {
public int[] sqlTypes() {
return new int[] { Types.BLOB };
}

public Class returnedClass() {
return byte[].class;
}

public boolean equals(Object x, Object y) {
return (x == y)
|| (x != null && y != null && java.util.Arrays.equals(
(byte[]) x, (byte[]) y));
}

public Object deepCopy(Object value) {
if (value == null)
return null;
byte[] bytes = (byte[]) value;
byte[] result = new byte[bytes.length];
System.arraycopy(bytes, 0, result, 0, bytes.length);
return result;
}

public boolean isMutable() {
return true;
}

/*
* (non-Javadoc)
*
* @see org.hibernate.usertype.UserType#hashCode(java.lang.Object)
*/
public int hashCode(Object arg0) throws HibernateException {
// TODO Auto-generated method stub
return 0;
}

/*
* (non-Javadoc)
*
* @see org.hibernate.usertype.UserType#disassemble(java.lang.Object)
*/
public Serializable disassemble(Object arg0) throws HibernateException {
// TODO Auto-generated method stub
return null;
}

/*
* (non-Javadoc)
*
* @see org.hibernate.usertype.UserType#assemble(java.io.Serializable,
* java.lang.Object)
*/
public Object assemble(Serializable arg0, Object arg1)
throws HibernateException {
// TODO Auto-generated method stub
return null;
}

/*
* (non-Javadoc)
*
* @see org.hibernate.usertype.UserType#replace(java.lang.Object,
* java.lang.Object, java.lang.Object)
*/
public Object replace(Object arg0, Object arg1, Object arg2)
throws HibernateException {
// TODO Auto-generated method stub
return null;
}

//and.. note the null check, oracle drivers return a null blob...
public Object nullSafeGet(ResultSet rs, String[] names, Object owner)
throws HibernateException, SQLException {
final Blob blob = rs.getBlob(names[0]);
return blob != null ? blob.getBytes(1, (int) blob.length()) : null;
}

public void nullSafeSet(PreparedStatement st, Object value, int index)
throws HibernateException, SQLException {
if (st instanceof oracle.jdbc.OraclePreparedStatement) {
oracle.sql.BLOB blob = oracle.sql.BLOB.createTemporary(st
.getConnection(), false, oracle.sql.BLOB.DURATION_SESSION);
blob.open(BLOB.MODE_READWRITE);
OutputStream out = blob.getBinaryOutputStream();
try {
out.write((byte[]) value);
out.flush();
out.close();
} catch (IOException e) {
throw new SQLException("failed write to blob" + e.getMessage());
}
blob.close();
((oracle.jdbc.OraclePreparedStatement) (st)).setBLOB(index, blob);
} else {
st.setBlob(index, Hibernate.createBlob((byte[]) value));
}

}

}

----------------------------------------------------
to convert
(i think this is not necessary,
you can work only with byte[])

Blob -> byte[] use method getBytes()
byte[] -> Blob use Hibernate.createBlob()

_________________
Pim.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 09, 2005 4:41 am 
Beginner
Beginner

Joined: Tue Jul 12, 2005 11:15 am
Posts: 29
A better solution is to use ojdc14.jar from oracle 10g
even if use oracle 9.
Thus, you avoid the creation of the custom class BinaryBlobType.
And the property "report" in your hibernate configuration file ReportsDO.hbm.xml become:

<property name="report" type="byte[]" column="YOUR_REPORTCOLUMN"/>

_________________
Pim.


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