Denis R.
Denis R.

Reputation: 818

How to specify SQL column type for a specific database in hibernate mapping file

Is it possible to set multiple SQL column types for an hibernate property depending on the dialect used ? If yes how ?

For example, if i have a column of type char[], I would like to create a CLOB type for Oracle and a Text type in SQL Server.

Upvotes: 2

Views: 1507

Answers (1)

ChssPly76
ChssPly76

Reputation: 100746

The short answer is "no, it's not possible".

The long answer is "kind of, but you probably don't want to do that":

Hibernate would do that automatically to a certain extent - that is, when you define (implicitly or explicitly) a property of certain Hibernate type, it will translate that type to appropriate RDBMS-specific SQL type. Dialect and its descendants are responsible for that translation.

You could influence how that translation occurs - again, to a certain extent - by extending the dialect(s) you're working with (like Oracle or SQL Server) and registering your own column types. You're likely better off relying on default Hibernate type mappings, though.

Upvotes: 1

Related Questions