For SQLServerDialect varbinary sql-type is generated for Serializable objects
-----------------------------------------------------------------------------
Key: HHH-1807
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1807
Project: Hibernate3
Type: Bug
Versions: 3.1.3
Environment: Hibernate 3.1.3, SQLServer
Reporter: Jaroslaw Odzga
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:
http://forum.hibernate.org/viewtopic.php?t=933683
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 there is a 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?
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
|