[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-1936?page=c...
]
Andrew Thompson commented on HHH-1936:
--------------------------------------
To break the original issue down a bit for clarity:
* Sybase *requires* that all auto-increment identity columns be of type numeric:
e.g. create table Foo ( foo_id numeric(9,0) identity )
* Sybase's JConnect drvier maps this to BigInteger (well BigDecimal really) in Java
code [*] see below
* Hibernate won't allow BigInteger as a primary key column for an object, due, I
think, to code in IdentityGeneratorFactory which checks explicitly
Result - we're caught between the proverbial rock and hard place.
So to partially get around this, we do this:
<id name="fooNum" column="foo_id"
type="com.example.hibernate.usertype.NumericType">
<generator class="identity" />
</id>
And NumericType is then a bit ghastly....
public class NumericType extends LongType {
public void set(PreparedStatement st, Object value, int index) throws HibernateException,
SQLException {
st.setBigDecimal( index, new BigDecimal(
BigInteger.valueOf(((Long)value).longValue())));
}
public int sqlType() {
return Types.NUMERIC;
}
}
Basically the field in our class is then a Long and we fake out the mapping from Long to
Numeric here.
There's a side issue where every time we want to use HQL or criteria queries, we have
to be very careful to always remember to call Query.setBigDecimal() and convert the Long
to an BigInteger manually. If we don't do that (i.e. we call setLong or let Hibernate
figure it out) then the Sybase JConnect driver emits SQL code which causes the database to
ignore the index (because the types don't match) and we table scan the table.
What we want to do is to change our class to use BigInteger as the id column, because
that's really what is needed with Sybase, but the checks in Hibernate won't allow
that.
IdentityGenerator doesn't support BigInteger as a valid identity
type.
----------------------------------------------------------------------
Key: HHH-1936
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-1936
Project: Hibernate3
Issue Type: Bug
Components: core
Affects Versions: 3.0.5
Environment: Hibernate 3.0.5, Sybase 12.05, Window/ Unix
Reporter: Leonid Shtivelman
Identity generator strategy doesn't support BigInteger as a valid id type. This
causes problem with Sybase which requires identity column to be numeric. It would seem an
obvious way to get around this problem is to set column mapping to long in hibernate xml
and the actual java object. This will solve obvious problem of creating identity, but
will cause performance problem on selection. In order for Sybase to use index for
parameter query the variable type of the parameter and column index type has to be the
same. If ones maps column type to Long, Hibernate will use JDBC method setLong(long) to
set value in the prepared statement. This will cause mismatch between parameter type and
column index type, and Sybase will not use index to locate index. As you can see this is
a big problem for anyone that is using identity columns Sybase and Hibernate
--
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....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira