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.  [ 1 post ] 
Author Message
 Post subject: Cannot upgrade to Hibernate 4 because of missing StructType
PostPosted: Wed Aug 29, 2012 5:13 pm 
Newbie

Joined: Wed Aug 29, 2012 3:58 pm
Posts: 1
To upgrade to Hibernate 4, I need a single-column basic StructType. In Hibernate 4, org.hibernate.type.BasicTypeRegistry contains single-column types such as arrays, blobs and clobs, but no type for java.sql.Types.STRUCT (id = 2002).

I have a pre-existing database field/column defined as an oracle.sql.STRUCT named DB_OBJECT_TYPE. In Hibernate 3, I was able to implement this as a custom UserType with the code at the bottom of this post.

With Hibernate 4, this code results in a class cast exception because the connection is proxied, even if
* I use "session.connection()" instead of "statement.getConnection()" or
* I use the session factory to get the session and use the connection inside "session.doWork( ... )"

So I tried to use the Hibernate 4 way, "StructType.INSTANCE.set( statement, values, index, session );" but
* There is no such thing as a StructType
* SerializableType maps to VARBINARY in Oracle
* Breaking up the java.sql.Types.STRUCT into its basic types will make it cover more than one field/column

Hibernate 3 code:

Code:
public int[] sqlTypes() {
  return new int[] {java.sql.Types.STRUCT};
}

public void nullSafeSet(PreparedStatement statement, Object value, int index, SessionImplementor session)
throws HibernateException, SQLException {
  if (value == null) {
      statement.setNull(index, java.sql.Types.STRUCT, DB_OBJECT_TYPE);
  } else {
      final MyDBObjectClass myDBObject = (MyDBObjectClass) value;
      final Object[] values = new Object[] { myDBObject.x, myDBObject.y, ... };
      final Connection connection = statement.getConnection();
      final oracle.sql.STRUCT myStruct = new oracle.sql.STRUCT(
        oracle.sql.StructDescriptor.createDescriptor(DB_OBJECT_TYPE, connection),
        connection, values);
      statement.setObject(index, myStruct, java.sql.Types.STRUCT);
  }
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.