[ 
https://issues.apache.org/jira/browse/OPENJPA-2534?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14272614#comment-14272614
 ] 

Mark Struberg commented on OPENJPA-2534:
----------------------------------------

I actually find this very hint not really useful at all. 

I currently face a pretty similar issue. My customer doesn't have boolean 
values represented as NUMBER(1) in his database but as CHAR(1) containing '1' 
and '0'. 

Of course I also have seen 'Y'/'N' and 'T'/'F' as well already! The problem is 
that Oracle didn't define any native datatype for boolean for a very long time.

I'm tempted to add it to DBDictionary and add an enum for those values

BOOLEAN_INT_01
BOOLEAN_STRING_01
BOOLEAN_STRING_YN
BOOLEAN_STRING_TF

and use them in DBDictionary#setBoolean.
Wdyt? Any better ideas?

PS: imo we cannot just have an Object booleanTrueRepresentation and Object 
booleanFalseRepresentation as we really need to invoke different methods on the 
PreparedStatement.

> A boolean is not converted correct when using the hint 'UseLiteralInSQL'.
> -------------------------------------------------------------------------
>
>                 Key: OPENJPA-2534
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-2534
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: sql
>    Affects Versions: 2.1.2, 2.2.1.1, 2.2.3, 2.3.1, 2.4.0
>            Reporter: Heath Thomann
>            Assignee: Rick Curtis
>            Priority: Critical
>         Attachments: OPENJPA-2534.patch
>
>
> The hint, 'openjpa.hint.UseLiteralInSQL', is not properly converting a 
> boolean to an int.  To illustrate this, lets take this entity:
> public class MyEntity implements Serializable {
>  @Id
>  private Integer pk;
>  private boolean flag;
> ..........
> With this entity, lets take this test:
> Query q = em.createQuery("SELECT f FROM MyEntity f WHERE f.flag = true");
> q.setHint("openjpa.hint.UseLiteralInSQL", "false");  //false is the default
> q.getResultList();
> With this code, the following SQL will be generated:
> SELECT t0.pk, t0.code, t0.code2, t0.flag FROM MyEntity t0 WHERE (t0.flag = ?) 
>  [params=(int) 1]
> Next, lets take this code:
> Query q = em.createQuery("SELECT f FROM MyEntity f WHERE f.flag = true");
> q.setHint("openjpa.hint.UseLiteralInSQL", "true");
> q.getResultList();
> With this code, the following SQL will be generated:
> SELECT t0.pk, t0.code, t0.code2, t0.flag FROM MyEntity t0 WHERE (t0.flag = 
> true)
> However, in the latter case where UseLiteralInSQL=true, the following SQL 
> should be generated:
> SELECT t0.pk, t0.code, t0.code2, t0.flag FROM MyEntity t0 WHERE (t0.flag = 
> '1')
> Thanks,
> Heath



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to