views:

1152

answers:

3

Hello,

the problem is as follows: We're using hibernate with annotations as O/R Mapper.

Some @Column annotations look like:

@Column(columnDefinition = "longblob", name = "binaryData", nullable = true)

or

@Column(columnDefinition = "mediumtext", name = "remark", nullable = true)

with the columnDefinition attributes being mysql specific

on postgres for example, the columnDefinition values should be "bytea" and "varchar(999999)"

and on oracle probably something else.

Problems arise currently at the time of Schema Export, e.g. when creating the DDL statements.

Possible workarounds that I can think of are - Hack some JDBC driver that does a text replace (e.g. longblob->bytea) for the DDL statements. That's ugly but will work somehow - Use hibernate xml configuration instead of annotations. That will probably work but I prefer annotations

Does anybody know any alternatives? Hibernate specific workarounds are ok, e.g. if the columnDefinition attribute can contain dialect specific values like

@Column(columnDefinition = "mysql->mediumtext, postgres->varchar(999999)", name = "remark", nullable = true)

Thanks Holger

+2  A: 
KLE
Thanks - I already have the columnDefinition properties as constants for easier searching. Didn't know that annotations can be overloaded though - thanks!
Thanks, I'm currently finishing the migration to @Lob / @Column(length=90000) annotations which I prefer over modifying the hibernate Dialect. However, that would probably be my second option if the first one failed.
@unknown Of course, the simpler the better :-).
KLE
+1  A: 

Why don't you use the database-agnostic annotations like:

  • @Lob (on a byte[] or a String property)
  • @Column(length=90000) (on a String property)

and see what columns will be generated in the database. They will most likely be of the types you want them to be.

Bozho
Hello,thanks I wasn't aware of that, that seems to work.Best regardsHolger
A: 

Hello,

thanks everybody for the help

using @Lob / @Column did the trick!

Best regards Holger