-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Recognizing "true" / "false" in HQL
PostPosted: Mon Nov 30, 2009 6:54 am 
Newbie

Joined: Mon Nov 30, 2009 6:30 am
Posts: 2
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.


Top
 Profile  
 
 Post subject: Re: Recognizing "true" / "false" in HQL
PostPosted: Mon Nov 30, 2009 8:39 am 
Newbie

Joined: Mon Nov 30, 2009 6:30 am
Posts: 2
Nevermind -

The default HqlSqlWalker / LiteralProcessor does exactly that.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.