-->
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.  [ 2 posts ] 
Author Message
 Post subject: Persisting Serializable Object to Oracle DB
PostPosted: Fri Oct 08, 2004 7:23 am 
Newbie

Joined: Tue Oct 05, 2004 9:21 am
Posts: 7
Location: Dublin, Ireland
Hibernate version:
Hibernate version 2.1

Mapping documents:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="ims.configuration.RecordedInError" table="recorded_in_error" lazy="false" >
<id name="id" access="field" type="integer" unsaved-value="null">
<column name="id" sql-type="numeric(10,0)"/>
<generator class="native"/>
</id>
<property name="rieUser" type="string" access="field" >
<column name="rie_user" length="30" />
</property>
<property name="rieDateTime" type="timestamp" access="field">
<column name="rie_datetime" />
</property>
<property name="rieRecord" type="serializable" access="field" >
<column name="rie_record" />
</property>
<property name="classIdentifier" type="integer" access="field" >
<column name="class_id" />
</property>
<property name="className" type="string" access="field" >
<column name="class_name" length="50" />
</property>
</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():

{
DomainObject obj = factory.getDomainObject(ClinicalNotes.class);
String className = obj.getClass().getName();
String shortClassName = className.substring(className.lastIndexOf(".")+1);

RecordedInError rieObj = new RecordedInError();
rieObj.setClassIdentifier(obj.getId());
rieObj.setRieRecord((Serializable)obj);
rieObj.setClassName(shortClassName);
rieObj.setRIEDateTime(new java.util.Date());
ims.configuration.User user = domainSession.getUser();
if (user != null)
rieObj.setRIEUser(user.getLogin());
factory.save((DomainObject)rieObj);
factory.delete(obj);

}
public class RecordedInError extends ims.domain.DomainObject implements java.io.Serializable
{
public static final int CLASSID = 1204100000;
private java.util.Date rieDateTime;
private String rieUser;
private Serializable rieRecord;
private Integer classIdentifier;
private String className;


public Serializable getRieRecord()
{
return rieRecord;
}

public void setRieRecord(Serializable record)
{
this.rieRecord = record;
}

public Integer getClassIdentifier()
{
return classIdentifier;
}

public void setClassIdentifier(Integer id)
{
this.classIdentifier = id;
}

public String getClassName()
{
return this.className;
}

public void setClassName(String name)
{
this.className = name;
}

public java.util.Date getRIEDateTime()
{
return rieDateTime;
}

public String getRIEUser()
{
return rieUser;
}

/**
* @param date
*/
public void setRIEDateTime(java.util.Date date)
{
rieDateTime = date;
}

/**
* @param user
*/
public void setRIEUser(String user)
{
rieUser = user;
}

public int getClassId() {
return CLASSID;
}


}


public abstract class DomainObject implements Comparable, java.io.Serializable {
private Integer id;
private int version;

public DomainObject() {

}

public Integer getId() {
return id;
}

public int getVersion()
{
return version;
}

public String toString() {
StringBuffer sb = new StringBuffer(super.toString());
sb.append("id:").append(id).append(".");
sb.append("timestamp:").append(version).append(".");
return sb.toString();
}

/**
* This DomainObject is equal to another if the other
* is not null and it has the same class, and the id is
* the same.
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object obj)
{
if (null == obj) {
return false;
}
if (obj.getClass().equals(this.getClass()))
{
//JME: 20040902: Test to see if Object identity will do.
//Hibernate documentation discourages equality by id
return (this == obj);
/*
DomainObject domainObject = (DomainObject) obj;
Integer id = this.getId();
if ( null == id ) {
// fall back on object equality
return (this == obj);
}
return (id.equals(domainObject.getId()));
*/
}
return false;

}

/**
* @see java.lang.Object#hashCode()
*/
public int hashCode()
{
//JME: 20040902: Test to see if Object identity will do.
//Hibernate documentation discourages equality by id
return super.hashCode();
/*
if ( null != id ) {
return id.hashCode();
}
else {
return super.hashCode();
}
*/
}

/**
* Comparision based on the id of this DomainObject and another.
* @throws ClassCastException if the object is null or not a
* DomainObject.
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
public int compareTo(Object o)
{
if (null == o) {
throw new ClassCastException("Can't compare with null.");
}
DomainObject domainObject = (DomainObject) o;
Integer thisId = getId();
if ( null == thisId ) {
thisId = new Integer( System.identityHashCode(this) );
}
Integer thatId = domainObject.getId();
if ( null == thatId ) {
thatId = new Integer( System.identityHashCode(domainObject) );
}
return thisId.compareTo(thatId);
}

public abstract int getClassId();
}


Full stack trace of any exception that occurs:
java.sql.SQLException: operation not allowed: streams type cannot be used in batching
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.driver.OraclePreparedStatement.addBatch(OraclePreparedStatement.java:3775)
at org.apache.commons.dbcp.DelegatingPreparedStatement.addBatch(DelegatingPreparedStatement.java:257)
at net.sf.hibernate.impl.BatchingBatcher.addToBatch(BatchingBatcher.java:30)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:468)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:442)
at net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:29)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2414)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2367)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2236)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at ims.domain.hibernate.Transaction.commit(Transaction.java:41)
at ims.domain.impl.DomainImplProxyHandler.invoke(DomainImplProxyHandler.java:73)
at $Proxy7.markAsRecordedInError(Unknown Source)
at ims.coe.forms.clinicalnotes.Logic.onBtnRIEClick(Logic.java:290)
at ims.coe.forms.clinicalnotes.Handlers$2.handle(Handlers.java:34)
at ims.framework.cn.controls.Button.fireEvent(Button.java:47)
at ims.framework.cn.Form.fireEvent(Form.java:72)
at ims.framework.cn.Form.fireEvent(Form.java:85)
at ims.framework.cn.CNHost.doGet(CNHost.java:638)
at ims.framework.cn.CNHost.doPost(CNHost.java:1469)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2417)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:193)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:781)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:549)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:589)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:666)
at java.lang.Thread.run(Unknown Source)

Name and version of the database you are using:
Oracle 9.2.0.1.0
The generated SQL (show_sql=true):
Hibernate: insert into recorded_in_error (rie_user, rie_datetime, rie_record, class_id, class_name, id) values (?, ?, ?, ?, ?, ?)
Debug level Hibernate log excerpt:

[quote]

I'm trying to store a serialized form of an object in an Oracle database. On save, I get the error 'operation not allowed: streams type cannot be used in batching'. Our application runs for both Sybase and Oracle, and the Sybase version runs fine. The database type for serializable type in Sybase is IMAGE, I currently have it as Long Raw in Oracle, though experience the same problems using BLOB.
I also tried opening a separate session for this insert alone, but to no avail.

Any suggestions??

[/qoute]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 31, 2005 6:22 pm 
Newbie

Joined: Sun May 02, 2004 2:52 pm
Posts: 5
I don't beleive that you can batch streams to Oracle. Try setting
Code:
hibernate.jdbc.batch_size 0
in hibernate.properties

_________________
John Sampson


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