Home » Developer & Programmer » JDeveloper, Java & XML » Varray in Java (Oracle 11, ojdbc6)
Varray in Java [message #419797] Tue, 25 August 2009 11:32
mrooven
Messages: 1
Registered: August 2009
Junior Member
Hello,

I have a problem with getting data from the db. I have a type:
create or replace type SOME_VECTOR as varray(5) of number;


and a table that contains an item of this type:
   CREATE TABLE "T1" 
 (	
    "T1_ID" NUMBER(18,0) NOT NULL ENABLE, 
    "VAL" SOME_VECTOR
  );


Now, I am trying to create an entity from the database. I use NetBeans (tried both Hibernate and TopLink) - it generates an entity like this:
package some.package;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

@Entity
@Table(name = "T1")
@NamedQueries({@NamedQuery(name = "T1.findAll", query = "SELECT t FROM T1 t"), @NamedQuery(name = "T1.findByT1Id", query = "SELECT t FROM T1 t WHERE t.t1Id = :t1Id")})
public class T1 implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "T1_ID")
    private Long t1Id;
    @Lob
    @Column(name = "VAL")
    private Object val;

    public T1() {
    }

    public T1(Long t1Id) {
        this.t1Id = t1Id;
    }

    public Long getT1Id() {
        return t1Id;
    }

    public void setT1Id(Long t1Id) {
        this.t1Id = t1Id;
    }

    public Object getVal() {
        return val;
    }

    public void setVal(Object val) {
        this.val = val;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (t1Id != null ? t1Id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof T1)) {
            return false;
        }
        T1 other = (T1) object;
        if ((this.t1Id == null && other.t1Id != null) || (this.t1Id != null && !this.t1Id.equals(other.t1Id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "some.package.T1[t1Id=" + t1Id + "]";
    }

}


I have one row inserted into the db:
insert into t1 (t1_id, val) values (1, SOME_VECTOR(1, 3, 5));


Now, I try to get it this way:
        EntityManager eMan = Persistence.createEntityManagerFactory("DatabaseTesterPU", connectionProperties).createEntityManager();
        Query query = eMan.createQuery("SELECT t FROM T1 t");
        List<T1> rs = query.getResultList();

        System.out.println("Results number: " + rs.size());

        for(T1 t1 : rs){
            System.out.println(t1.toString());
        }


I receive an exception:
SEVERE: Invalid column type: getBLOB not implemented for class oracle.jdbc.driver.T4CNamedTypeAccessor
Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute query
(...)
Caused by: org.hibernate.exception.GenericJDBCException: could not execute query
(...)
Caused by: java.sql.SQLException: Invalid column type: getBLOB not implemented for class oracle.jdbc.driver.T4CNamedTypeAccessor
        at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)
        at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:112)
        at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:173)
        at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:229)
        at oracle.jdbc.driver.Accessor.unimpl(Accessor.java:375)
        at oracle.jdbc.driver.Accessor.getBLOB(Accessor.java:1352)
        at oracle.jdbc.driver.OracleResultSetImpl.getBLOB(OracleResultSetImpl.java:1215)
        at oracle.jdbc.driver.OracleResultSetImpl.getBlob(OracleResultSetImpl.java:465)
        at oracle.jdbc.driver.OracleResultSet.getBlob(OracleResultSet.java:380)
        at org.hibernate.type.BlobType.get(BlobType.java:57)
        at org.hibernate.type.BlobType.nullSafeGet(BlobType.java:111)
        at org.hibernate.type.AbstractType.hydrate(AbstractType.java:81)
        at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2096)
        at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1380)
        at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1308)
        at org.hibernate.loader.Loader.getRow(Loader.java:1206)
        at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:580)
        at org.hibernate.loader.Loader.doQuery(Loader.java:701)
        at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
        at org.hibernate.loader.Loader.doList(Loader.java:2220)
        ... 9 more


I've tried changing the type of entity field from Object to BigDecimal[], Double[], oracle.sql.ARRAY and some other - it has changed the exception to:
INFO: could not read column value from result set: ALIGN3_13_; could not deserialize
Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.type.SerializationException: could not deserialize
(...)
Caused by: org.hibernate.type.SerializationException: could not deserialize
        at org.hibernate.util.SerializationHelper.deserialize(SerializationHelper.java:217)
        at org.hibernate.util.SerializationHelper.deserialize(SerializationHelper.java:240)
        at org.hibernate.type.SerializableType.fromBytes(SerializableType.java:82)
        at org.hibernate.type.SerializableType.get(SerializableType.java:39)
        at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:163)
        at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:154)
        at org.hibernate.type.AbstractType.hydrate(AbstractType.java:81)
        at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2096)
        at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1380)
        at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1308)
        at org.hibernate.loader.Loader.getRow(Loader.java:1206)
        at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:580)
        at org.hibernate.loader.Loader.doQuery(Loader.java:701)
        at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
        at org.hibernate.loader.Loader.doList(Loader.java:2220)
        at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
        at org.hibernate.loader.Loader.list(Loader.java:2099)
        at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
        at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
        at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
        at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
        at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
        at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:65)
        ... 2 more
Caused by: java.io.StreamCorruptedException: invalid stream header: 88010E01
        at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:783)
        at java.io.ObjectInputStream.<init>(ObjectInputStream.java:280)
        at org.hibernate.util.SerializationHelper$CustomObjectInputStream.<init>(SerializationHelper.java:252)
        at org.hibernate.util.SerializationHelper.deserialize(SerializationHelper.java:209)


I've tried google, tutorials and many both rational and insane combinations - nothing helps. I would be most grateful for any helpful tip.
Previous Topic: Message Internal Error: Inconsistent catalog view
Next Topic: How to SELECT * FROM XML Document
Goto Forum:
  


Current Time: Sun Dec 11 04:21:32 CST 2016

Total time taken to generate the page: 0.07813 seconds