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.  [ 18 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Support for Oracle B File
PostPosted: Fri Sep 16, 2005 12:30 pm 
Newbie

Joined: Fri Apr 22, 2005 3:21 pm
Posts: 12
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:2.1.3

I am looking for info on Oracle B File support by hibernate. Could someone please point me to any available info.

I am having trouble finding info on this on www.hobernate.org. Amlan


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 16, 2005 1:47 pm 
Contributor
Contributor

Joined: Thu Nov 06, 2003 9:49 pm
Posts: 104
Location: New York, NY
Never heard of a "B File". I've been using ORACLE for years (unfortunately).


Top
 Profile  
 
 Post subject: BFile
PostPosted: Fri Sep 16, 2005 2:33 pm 
Newbie

Joined: Fri Apr 22, 2005 3:21 pm
Posts: 12
(1, null, 90.0, BFILENAME('opportunity_dir', 'filename.Doc'));

The way BFile works is ... like the above sample insert statement. Essentially the file is stored on the file system as opposed to a blob or a clob ... but the reference to it is stored in the table .... I am curious how hiberntae handles this....


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 16, 2005 4:06 pm 
Contributor
Contributor

Joined: Thu Nov 06, 2003 9:49 pm
Posts: 104
Location: New York, NY
That's a really ORACLE-specific feature so I'd be pretty surprised if Hibernate's built in Dialects handled that.

I suppose you could write a Dialect/UserType that supported it. But at that piont it would probably be much easier to use JDBC in your DAOs. That's what I did in order to get around the bugs in ORACLE's JDBC drivers.


Top
 Profile  
 
 Post subject: Follow up on ORacle BFILENAME
PostPosted: Fri Sep 16, 2005 4:11 pm 
Newbie

Joined: Fri Apr 22, 2005 3:21 pm
Posts: 12
Hi Joshua or anyone who can help,

Please look at the following publication from Oracle.

http://www.oracle.com/technology/tech/j ... a96654.pdf

Please look at 151 of 584.

Let me know if there is anything I can provide for this ...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 26, 2005 10:13 am 
Newbie

Joined: Mon Sep 26, 2005 10:00 am
Posts: 3
Hi there !

I am trying to implement the UserType class in order to deal with Oracle BFiles.

Could someone help me, because I have no idea how to correctly implements the following methods :
Code:
public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException;

public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException;

public Object deepCopy(Object value) throws HibernateException;


Thank u

PS : The rest of the class looks like this :

Code:
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import oracle.jdbc.driver.OracleTypes;
import oracle.sql.BFILE;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.UserType;

public final class BFileType implements UserType {

   private static final int BFILE_TYPE = OracleTypes.BFILE;
   private static final Class RETURNED_CLASS = BFILE.class;
      
   public int[] sqlTypes() {
      return new int[]{BFILE_TYPE};
   }

   public Class returnedClass() {
      return RETURNED_CLASS;
   }

   public boolean equals(Object x, Object y) throws HibernateException {
      BFILE bx = (BFILE)x;
      BFILE by = (BFILE)y;      
      if (bx == by){
         return true;
      }
      if (bx == null || by == null){
         return false;
      }
      return bx.equals(by);
   }

   public boolean isMutable() {
      return false;
   }

}
    Code:


    Top
     Profile  
     
     Post subject:
    PostPosted: Mon Sep 26, 2005 11:31 am 
    Expert
    Expert

    Joined: Sat Jun 12, 2004 4:49 pm
    Posts: 915
    It is better that define return class byte[] and make methods like this :

    Code:
            public Object nullSafeGet(ResultSet rs, String[] names, Object owner)
             throws HibernateException, SQLException {
          BFILE file = (BFILE) rs.getObject(names[0]);
          if (file == null)
             return null;
          return file.getBytes();
       }
       
       public void nullSafeSet(PreparedStatement st, Object value, int index)
             throws HibernateException, SQLException {
          if (value == null)
             st.setObject(index,null);
          else {
             BFILE file = new BFILE((OracleConnection) st.getConnection(),(byte[])value);
          }
          
       }


    Top
     Profile  
     
     Post subject:
    PostPosted: Mon Sep 26, 2005 11:34 am 
    Hibernate Team
    Hibernate Team

    Joined: Tue Aug 26, 2003 6:10 am
    Posts: 8615
    Location: Neuchatel, Switzerland (Danish)
    also consider providing your own sql via <sql-insert> in the mappings (only if the customtype is not enough)

    _________________
    Max
    Don't forget to rate


    Top
     Profile  
     
     Post subject:
    PostPosted: Mon Sep 26, 2005 11:39 am 
    Newbie

    Joined: Mon Sep 26, 2005 10:00 am
    Posts: 3
    Thank u for your reply snpesnpe !

    I ll try your suggestion !

    Any idea of what is the 'owner' parameter in the nullSafeGet method ?


    Top
     Profile  
     
     Post subject:
    PostPosted: Mon Sep 26, 2005 11:40 am 
    Expert
    Expert

    Joined: Sat Jun 12, 2004 4:49 pm
    Posts: 915
    entity (table)


    Top
     Profile  
     
     Post subject:
    PostPosted: Wed Oct 25, 2006 3:22 pm 
    Newbie

    Joined: Wed Oct 25, 2006 3:01 pm
    Posts: 2
    Hi everybody,

    I have a problem with nullSafeSet in this line:

    BFILE file = new BFILE((OracleConnection) st.getConnection(),(byte[])value);

    I am using ojdbc14-10.2.0.1.0.jar driver and st.getConnection() return
    T4CConnection instead OracleConnection. It throws a ClassCastException.

    What can i do?

    Thanks.

    Sorry by my english :)


    Configurations:

    Hibernate - hibernate-3.1.3
    Spring - spring-1.2.
    Driver - ojdbc14-10.2.0.1.0
    Dialect - org.hibernate.dialect.Oracle9Dialect
    DataSource - org.springframework.jndi.JndiObjectFactoryBean

    Exception:

    NullableType.nullSafeSet(87) | could not bind value 'org.xxx.jdbc.support.OracleBFile@8c0d5d' to parameter: 9; org.apache.tomcat.dbcp.dbcp.PoolableConnection
    Caused by: java.lang.ClassCastException: org.apache.tomcat.dbcp.dbcp.PoolableConnection
    at org.xxx.type.BFileType.set(BFileType.java:56)
    at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:83)
    at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:60)


    Top
     Profile  
     
     Post subject:
    PostPosted: Thu Oct 26, 2006 2:08 am 
    Hibernate Team
    Hibernate Team

    Joined: Tue Aug 26, 2003 6:10 am
    Posts: 8615
    Location: Neuchatel, Switzerland (Danish)
    this is a current limitation caused by the need for us to safeguard the connection.

    See http://opensource.atlassian.com/project ... e/HHH-1737

    _________________
    Max
    Don't forget to rate


    Top
     Profile  
     
     Post subject:
    PostPosted: Thu Oct 26, 2006 2:10 am 
    Hibernate Team
    Hibernate Team

    Joined: Tue Aug 26, 2003 6:10 am
    Posts: 8615
    Location: Neuchatel, Switzerland (Danish)
    sorry this is not a problem of the proxy!

    This is because you are using a connectionpool....you need to lookup in the connectionpool doc how you can get the real connection.

    _________________
    Max
    Don't forget to rate


    Top
     Profile  
     
     Post subject:
    PostPosted: Thu Oct 26, 2006 10:13 am 
    Newbie

    Joined: Wed Oct 25, 2006 3:01 pm
    Posts: 2
    Thanks max !!


    Top
     Profile  
     
     Post subject:
    PostPosted: Thu Oct 26, 2006 10:31 am 
    Hibernate Team
    Hibernate Team

    Joined: Tue Aug 26, 2003 6:10 am
    Posts: 8615
    Location: Neuchatel, Switzerland (Danish)
    still nothing to do with hibernate. hibernate gets the connection from your pool and don't mess with it.

    _________________
    Max
    Don't forget to rate


    Top
     Profile  
     
    Display posts from previous:  Sort by  
    Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 18 posts ]  Go to page 1, 2  Next

    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.