-->
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.  [ 3 posts ] 
Author Message
 Post subject: oracle blob and tomcat.
PostPosted: Thu Mar 11, 2004 4:55 am 
Newbie

Joined: Thu Mar 11, 2004 3:57 am
Posts: 4
Hallo,

we are using hiberante 2.1 with oracle 9i in a tomcat 4.1.29 environment.

I run in the following problem:

I use the jndi for the connection pooling for hibernate and reference this
in the hibernate properties:


Code:
hibernate.connection.datasource=java:comp/env/jdbc/webbox
#hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver
#hibernate.connection.url=jdbc:oracle:thin:@20.21.22.23:1521:<sid>
#hibernate.connection.username=<username>
#hibernate.connection.password=<passwort>
#hibernate.connection.pool_size=30
#hibernate.show_sql=true
#
hibernate.dialect=net.sf.hibernate.dialect.Oracle9Dialect
#
In the server.xml, the jndi configuration is done:

Code:
<ResourceParams name="jdbc/webbox">
         <parameter>
         <name>validationQuery</name>
        <value>select * from dual</value>
      </parameter>
      <parameter>
        <name>maxWait</name>
        <value>5000</value>
      </parameter>
      <parameter>
        <name>maxActive</name>
        <value>4</value>
      </parameter>
      <parameter>
        <name>password</name>
        <value>thePasswort</value>
      </parameter>
      <parameter>
        <name>url</name>
        <value>jdbc:oracle:thin:@20.21.22.23:1521:sid</value>               
      </parameter>
      <parameter>
        <name>driverClassName</name>
        <value>oracle.jdbc.driver.OracleDriver</value>
      </parameter>
      <parameter>
        <name>maxIdle</name>
        <value>2</value>
      </parameter>
      <parameter>
        <name>username</name>
        <value>theUser</value>
      </parameter>
    </ResourceParams>


This environment works for all select update insert , what ever, expect
if I try to insert or update a blob field.

I got a class cast exception

java.lang.ClassCastException
at oracle.jdbc.driver.OracleConnection.physicalConnectionWithin(OracleConnection.java:5041)
at oracle.sql.BLOB.createTemporary(BLOB.java:767)
at com.csc.webbox.btasks.kunde.ObjektBT.kalkulationsDateiSpeichern(ObjektBT.java:231)
at com.csc.webbox.btasks.kunde.ObjektBT.kalkSpeichern(ObjektBT.java:164)
at com.csc.webbox.btasks.kunde.ObjektBT.kalkulationSpeichern(ObjektBT.java:112)
at com.csc.webbox.presentation.kalkulator.actions.ObjektKalkulationAnlegenAction.doExecute(ObjektKalkulationAnlegenAction.java:82)
at com.csc.webbox.presentation.WebboxAction.execute(WebboxAction.java:67)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)

The code which leads to this exception is:

Code:
/**   not active code segment   ***************   
         
if(kd == null)
{
   kd = new Kalkdatei();
   byte [] dummyBuffer = new byte[32];
   dummyBuffer = (new String("DummyBlob")).getBytes();
   kd.setKalkulationid(kalk.getKalkulationid());      
   kd.setDatei(Hibernate.createBlob(dummyBuffer));
   Persistence.save(kd);
   newKD = true;
}
         

   Persistence.flush();
   Persistence.refresh(kd, LockMode.UPGRADE);
   oracle.sql.BLOB blob = (oracle.sql.BLOB) kd.getDatei();
   OutputStream out = blob.getBinaryOutputStream();
   out.write(kalk.getData());

   out.close();
   Persistence.flush();
****** end inactiv code segment    **/
         

oracle.sql.BLOB blob = oracle.sql.BLOB.createTemporary(Persistence.connection(), false, oracle.sql.BLOB.DURATION_SESSION);
           
blob.open(oracle.sql.BLOB.MODE_READWRITE);
OutputStream out = blob.getBinaryOutputStream();
           
out.write(kalk.getData() );
  out.flush();
  out.close();

blob.close();


I have also tried the inactive code segement above, but the same problem, i got a class cast exception in the line
Quote:
oracle.sql.BLOB blob = (oracle.sql.BLOB) kd.getDatei();

Thats the bad news.
The good news is, if I replace the jndi connection pool with the hibernate connection pool (commented lines in the hibernate.properties) all both solution works fine.

What is wrong in the jndi solution in conjunction with oracle blobs ?

Thanks a lot

Jurgen


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 11, 2004 4:57 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Use a debugger and check what class you actually have when getting a classCastException?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 11, 2004 5:37 am 
Newbie

Joined: Thu Mar 11, 2004 3:57 am
Posts: 4
Hallo,


the first version I have used is the inactive section shown in my post before.
I have used the debugger to examine the actual class.
In this case the class returned in this line is a oracle.sql.BLOB class
Quote:
oracle.sql.BLOB blob = (oracle.sql.BLOB) kd.getDatei();


After this I have tried the the code based on direct use of the
oracle classes but this I haven't checked in the debugger because
I have not the source code of the class which raise this exception

Quote:
at oracle.jdbc.driver.OracleConnection.physicalConnectionWithin(OracleConnection.java:5041)


The Class mapped to the Table looks like:
Code:




import java.sql.Blob;

/**
* @author jliebman
* Datum 16.02.2004

* */
public class Kalkdatei
{
   Long kalkulationid;
   Blob datei;
   /**
    * @return
    */
   public  Blob getDatei()
   {
      return datei;
   }

   /**
    * @param blob
    */
   public void setDatei(Blob blob)
   {
      datei = blob;
      
   }

   /**
    * @return
    */
   public Long getKalkulationid()
   {
      return kalkulationid;
   }

   /**
    * @param long1
    */
   public void setKalkulationid(Long long1)
   {
      kalkulationid = long1;
   }

}



The mapping of the table to this class is shown here

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
   
<hibernate-mapping>
<!--
    Created by the Middlegen Hibernate plugin

    http://boss.bekk.no/boss/middlegen/
    http://hibernate.sourceforge.net/
-->

<class
    name="com.csc.webbox.objects.hibernate.Kalkdatei"
    table="KALKDATEI"
>

    <id
        name="kalkulationid"
        type="java.lang.Long"
        column="kalkulationid"
    >
        <generator class="assigned" />
    </id>
    <property
        name="datei"
        column="KALK"

    />

</class>
</hibernate-mapping>


Thanks


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