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: SQLServerDialect and varbinary type for Serializable objects
PostPosted: Wed May 31, 2006 12:18 pm 
Newbie

Joined: Mon May 29, 2006 11:57 am
Posts: 2
Hibernate version: 3.1.3 and above

The schema export generates "varbinary(xxx)" if the mapping document specifies "serializable" for a particular field. In SQL server varbinary has a limit of 8000 bytes (less if there is more data on the row). In order to store more than this, the data type should to be "IMAGE" instead of "varbinary(xxx)".

This problem has already been investigated:
<a href='http://forum.hibernate.org/viewtopic.php?t=933683'&gt;http://forum.hibernate.org/viewtopic.php?t=933683&lt;/a>

The resolution has been proposed and applied by simply changing the SQLServerDialect where two lines:
registerColumnType( Types.VARBINARY, "image" );
registerColumnType( Types.VARBINARY, 8000, "varbinary($l)" );
has been added to the constructor.

However this solution does not work properly. Here is example:

example.hibernate.Person.java file:

package example.hibernate;
import java.io.Serializable;
/**
* @hibernate.class
*/
public class Person {
private Serializable attributes;
private Long PersonId;
/**
* @hibernate.id
* generator-class="hilo"
*/
public Long getPersonId() {
return PersonId;
}
public void setPersonId(Long personId) {
PersonId = personId;
}
/**
* @hibernate.property
*/
public Serializable getAttributes() {
return attributes;
}
public void setAttributes(Serializable attributes) {
this.attributes = attributes;
}
}

generated mapping by xdoclet:
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="example.hibernate.Person">

<id
name="personId"
column="personId"
type="java.lang.Long">
<generator class="hilo">
</generator>
</id>

<property
name="attributes"
type="java.io.Serializable"
update="true"
insert="true"
column="attributes"
/>

</class>

</hibernate-mapping>

and the generated sql script by schema export:

create table Person (personId numeric(19,0) not null, attributes varbinary(255) null, primary key (personId));
create table hibernate_unique_key ( next_hi int );
insert into hibernate_unique_key values ( 0 );


After investigating data types definition I came up with the following sollution:
replace
registerColumnType( Types.VARBINARY, 8000, "varbinary($l)" );
with
registerColumnType( Types.VARBINARY, 8000, "image" );

Works fine now but I think maybe it is the better way - simply force Hibernate to use VARBINARY without specified size in case of Serializable objects.

Also, shouldn't be
super();
the first line of SQLServerDialect constructor?

_________________
Jaroslaw


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.