2

I don't have much background on the technologies below so any help would be appreciated. Please feel free to ask questions if something's not clear.

I'm currently working on a migration project wherein we're updating a number of technologies including:

  1. Sybase - from 12.x to 15.7
  2. JConnect - from several versions to 7.0.7_SP130

Now, our apps are deployed on to JBoss 4.x and use Hibernate 3.2.4.sp1. In the old DB, we have a number of custom datatypes that look something like this (sorry, would have loved to put this in table format, but I don't know how to here...) :

  • Custom datatype: TYPE1, Base datatype: image
  • Custom datatype: TYPE2, Base datatype: tinyint

Some columns in our DDL use the custom datatypes:

CREATE TABLE y (
   our_column_name TYPE1,
   ...
);

When the server is started up, I get the following error message:

... javax.persistence.PersistenceException: org.hibernate.HibernateException: Wrong column type: our_column_name, expected: image

which is not what happens in the old setup. Do take note that of all the custom datatypes we've defined, only those with image and tinyint have issues; the others are recognized and throw no error.

We've run a trace on the JConnect driver and it appears that it's retrieving the correct datatype, which is why I'm now focusing on the HibernateException. I've seen a couple of posts similar to this one (occurring on different DBs), but basically, they gave similar workarounds:

  1. One site like this one, it's suggested that we alter the DB table's column to use the base datatype instead of the custom datatype. We've done this by changing our_column_name's datatype to image. Once this was done and the server was restarted, the error goes away. However, it does not explain why or what caused the issue.

  2. This suggested the use of JPA annotations' @Column(columnDefinition='image'). We've tried this as well, but it doesn't seem to have any effect on the startup (i.e. error still occurred).

  3. In the same link as #2, it was suggested that the SQL Dialect be extended. However, I don't think this is feasible - only 2 custom datatypes (image and tinyint) seem to be causing the problems on our end so this may be overkill.

  4. This site suggests the removal of hibernate.hbm2ddl.auto=validate from persistence.xml. Have not tried this as we need the validation to be in place.

  5. Use the datatype "LOB" instead

I've also tried checking out Hibernate's code since the exception was thrown here - org.hibernate.mapping.Table.validateColumns(Table.java:261), which pretty much points to this line:

boolean typesMatch = (col.getSqlType(dialect, mapping).startsWith(columnInfo.getTypeName().toLowerCase())) || (columnInfo.getTypeCode() == col.getSqlTypeCode(mapping));

However, Hibernate's API documentation is a little wanting in details so I'm having some difficulty in tracing this at the moment...

Any ideas on what's causing the exception? If it's working in the old version, was wondering on what changes in Hibernate (or Sybase for that matter) can cause this?

This document suggests that Hibernate is tested against Sybase 15.7 so I'm at a loss where to continue looking. And would #1 above be the best workaround? If so, any ideas why base types should be used instead of custom datatypes (which would, in essence, render custom datatypes useless...)

Thanks again in advance!

EDIT:

Tried the following:

  1. If @Column(columnDefinition='my_custom_datatype') is used, then the error goes away.
  2. If hibernate.hbm2ddl.auto=validate is removed from persistence.xml, the error goes away.

I'm really suspecting it's a hibernate issue...

Community
  • 1
  • 1
callie16
  • 570
  • 1
  • 11
  • 26

2 Answers2

7

This is similar in nature to this question on SO i.e. typesMatch in the code in my query above will be false because the values being returned by col and columnInfo are different - one is returning the base datatype, the other is returning the custom user type.

So, to deal with it, a number of workarounds are possible (and I've mentioned it in my post above) -

  1. Remove hibernate.hbm2ddl.auto=validate if you can.
  2. Change the column datatypes directly in DB, which I think is the next fastest approach.
  3. Use @Column(columnDefinition='my_custom_datatype') in the Java class.
Community
  • 1
  • 1
callie16
  • 570
  • 1
  • 11
  • 26
0

If you use @DiscriminatorColumn remember to put there too. Like this:

@DiscriminatorColumn(name = "MyTableName", discriminatorType = DiscriminatorType.STRING, columnDefinition = "char")

and into the attribute

    @Column(name="MyColumnName",nullable = true, insertable = true, updatable = true, length = 1, columnDefinition = "char")
    private String type;