Hi -
Here is my problem. In our software we have clients issuing HQL directly to the application server. We started out by using PostgreSQL as DB backend but now partners are requesting the possibility to use MS SQL. So my first task was to write new hibernate mappings compatible with SQL.
So for instance boolean default "true":
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-access="field" package="entity.hibernate">
<class name="Entity" schema="Core" table="Entity" lazy="true"
abstract="true">
<id name="id" type="long">
<column name="ID" />
<generator class="sequence">
<param name="sequence">Core.Entity_ID_Sequence</param>
</generator>
</id>
<!-- Fields -->
<property name="active" type="boolean">
<column name="Active" not-null="true" default="true" />
</property>
</class>
</hibernate-mapping>
has become "1":
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-access="field" package="entity.hibernate">
<class name="Entity" schema="Core" table="Entity" lazy="true"
abstract="true">
<id name="id" type="long">
<column name="ID" />
<generator class="identity" />
</id>
<!-- Fields -->
<property name="active" type="boolean">
<column name="Active" not-null="true" default="1" />
</property>
</class>
</hibernate-mapping>
As aforementioned we have clients that inject HQL into the application server. So instead of making all client code, there is a lot and on different platform, configurable to use "true" or "1" / "false" or "0", my question is: Is there a smart way to do it on the server?
My idea was somehow identifying the "true" / "false" as tokens in HQL lexing / parsing and then use Dialect.toBooleanValueString(bool). But I am not sure if that is the correct approach.