-->
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: problem with BFile user type mapping
PostPosted: Wed Nov 19, 2008 5:45 am 
Newbie

Joined: Wed Nov 19, 2008 4:58 am
Posts: 2
I need use BFile like storage type for my files. I read all of posts in this forum about BFile. But I can not solve this exception:

Caused by: org.hibernate.MappingException: Could not determine type for: bfile, for columns: [org.hibernate.mapping.Column(file)]

my class:

Code:
@TypeDef(name = "bfile", typeClass = BFileType.class)
abstract public class GeneralFile extends BaseWithId {

    private String name;
    private String description;

    private byte[] file;
    ...

    @Type(type = "bfile")
    byte[] getFile() {
        return file;
    }


my user type:

Code:
import java.io.Serializable;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import oracle.jdbc.OracleConnection;
import oracle.jdbc.OracleTypes;
import oracle.sql.BFILE;

import org.hibernate.HibernateException;
import org.hibernate.usertype.UserType;
import org.hibernate.util.EqualsHelper;

public final class BFileType implements UserType {
    private static final int BFILE_TYPE = OracleTypes.BFILE;
    private static final Class RETURNED_CLASS = byte[].class;

    public int[] sqlTypes() {
        return new int[] { BFILE_TYPE };
    }

    public Class returnedClass() {
        return RETURNED_CLASS;
    }

    public boolean equals(Object x, Object y) throws HibernateException {
        return EqualsHelper.equals(x, y);
    }

    public boolean isMutable() {
        return false;
    }

    public Object assemble(Serializable cached, Object owner) throws HibernateException {
        return cached;
    }

    public Object deepCopy(Object value) throws HibernateException {
        return value;
    }

    public Serializable disassemble(Object value) throws HibernateException {
        return (Serializable) value;
    }

    public int hashCode(Object x) throws HibernateException {
        return x.hashCode();
    }

    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);
            file.setLocator("".getBytes());
            st.setObject(index, file);
        }
    }

    public Object replace(Object original, Object target, Object owner) throws HibernateException {
        return original;
    }
}


what I am doing wrong?

configuration:
hibernate 3.2.5
Oracle Database 11g[/code][/b]


Top
 Profile  
 
 Post subject: Re: problem with BFile user type mapping
PostPosted: Thu Nov 20, 2008 3:28 am 
Newbie

Joined: Wed Nov 19, 2008 4:58 am
Posts: 2
nobody knows


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.