You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by "sharath.h (JIRA)" <ji...@apache.org> on 2007/04/14 01:15:16 UTC

[jira] Created: (OPENJPA-217) query param value issue in select query

query param value issue in select query
---------------------------------------

                 Key: OPENJPA-217
                 URL: https://issues.apache.org/jira/browse/OPENJPA-217
             Project: OpenJPA
          Issue Type: Bug
          Components: jpa, query
    Affects Versions: 0.9.6
            Reporter: sharath.h
            Priority: Minor


Consider a scenario where we have an entity class as shown below:
class A
{
 long id;
String str1;
String str2;
}
Say for str2 attribute there will be length constraint something like 
<basic name="str2" >
          <column name="col2"  length="4"/>        
 </basic>

Now say i have a jpql select query as shown below :
Query q = em.createQuery("select t from A t where t.str2:paramvalue");
q.setParameter("paramvalue", "23");

The above query return empty result set even though the records are present in table.
But when i set the value from "23" to "23  " (i.e. with trailing 2 spaces).


Can the padding of additional empty spaces be taken care default by jpa itself for select kind of queries.



-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (OPENJPA-217) query param value issue in select query

Posted by "sharath.h (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-217?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

sharath.h updated OPENJPA-217:
------------------------------

    Description: 
Consider a scenario where we have an entity class as shown below:
class A
{
 long id;
String str1;
String str2;
}
Say for str2 attribute there will be length constraint something like 
<basic name="str2" >
          <column name="col2"  length="4"/>        
 </basic>

Now say i have a jpql select query as shown below :
Query q = em.createQuery("select t from A t where t.str2:paramvalue");
q.setParameter("paramvalue", "23");

The above query return empty result set even though the records are present in table.
But when i set the value from "23" to "23  " (i.e. with trailing 2 spaces) it works.


Can the padding of additional empty spaces be taken care default by jpa itself for select kind of queries.



  was:
Consider a scenario where we have an entity class as shown below:
class A
{
 long id;
String str1;
String str2;
}
Say for str2 attribute there will be length constraint something like 
<basic name="str2" >
          <column name="col2"  length="4"/>        
 </basic>

Now say i have a jpql select query as shown below :
Query q = em.createQuery("select t from A t where t.str2:paramvalue");
q.setParameter("paramvalue", "23");

The above query return empty result set even though the records are present in table.
But when i set the value from "23" to "23  " (i.e. with trailing 2 spaces).


Can the padding of additional empty spaces be taken care default by jpa itself for select kind of queries.




> query param value issue in select query
> ---------------------------------------
>
>                 Key: OPENJPA-217
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-217
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: jpa, query
>    Affects Versions: 0.9.6
>            Reporter: sharath.h
>            Priority: Minor
>
> Consider a scenario where we have an entity class as shown below:
> class A
> {
>  long id;
> String str1;
> String str2;
> }
> Say for str2 attribute there will be length constraint something like 
> <basic name="str2" >
>           <column name="col2"  length="4"/>        
>  </basic>
> Now say i have a jpql select query as shown below :
> Query q = em.createQuery("select t from A t where t.str2:paramvalue");
> q.setParameter("paramvalue", "23");
> The above query return empty result set even though the records are present in table.
> But when i set the value from "23" to "23  " (i.e. with trailing 2 spaces) it works.
> Can the padding of additional empty spaces be taken care default by jpa itself for select kind of queries.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (OPENJPA-217) query param value issue in select query

Posted by "Jacek Laskowski (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-217?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12488863 ] 

Jacek Laskowski commented on OPENJPA-217:
-----------------------------------------

I have tested it out with the latest version of OpenJPA built from the sources and it worked fine.

31  derbyPU  INFO   [main] openjpa.Runtime - Starting OpenJPA 0.9.8-incubating-SNAPSHOT

Here're my test files for reference:

package pl.jaceklaskowski.jpa.entity;

import javax.persistence.Entity;
import javax.persistence.Id;

@Entity
public class A {
    long id;
    String str1;
    String str2;

    @Id
    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getStr1() {
        return str1;
    }

    public void setStr1(String str1) {
        this.str1 = str1;
    }

    public String getStr2() {
        return str2;
    }

    public void setStr2(String str2) {
        this.str2 = str2;
    }

    public String toString() {
        return "id=" + getId() + ", str1=" + getStr1() + ", str2=" + getStr2();
    }
}

and the test itself:

package pl.jaceklaskowski.jpa.issue;

import javax.persistence.Query;

import org.testng.annotations.Test;

import pl.jaceklaskowski.jpa.BaseTest;
import pl.jaceklaskowski.jpa.entity.A;

public class Openjpa217 extends BaseTest {

    @Test(dependsOnMethods = { "utworzPracownikow" })
    public void testStringLengthQueryParam() {
        {
            A a = new A();
            a.setStr2("23");

            em.getTransaction().begin();
            em.persist(a);
            em.getTransaction().commit();
        }
        {
            Query q = em.createQuery("SELECT t from A t where t.str2 = :paramvalue");
            q.setParameter("paramvalue", "23");
            A a = (A) q.getSingleResult();
            assert a.getStr2().length() == 2;
        }
        {
            Query q = em.createQuery("SELECT t from A t where t.str2 = :paramvalue");
            q.setParameter("paramvalue", "23  ");
            A a = (A) q.getSingleResult();
            assert a.getStr2().length() == 2;
        }
    }
}

I kept getting BUILD SUCCESSFUL with no test errors inbetween.

$ mvn -Dtest=Openjpa217 clean test
...
-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running pl.jaceklaskowski.jpa.issue.Openjpa217
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9 seconds
[INFO] Finished at: Sat Apr 14 15:24:35 CEST 2007
[INFO] Final Memory: 11M/254M
[INFO] ------------------------------------------------------------------------

I attempted to run it against the version in question - 0.9.6-incubating, but couldn't get it to work as far as the schema generation's concerned so I left it as an exercise for others to try out.

47  INFO   [main] openjpa.Runtime - Starting OpenJPA 0.9.6-incubating

The solution is to upgrade the OpenJPA version to the latest one available from m2 repo or the download page or build it locally from the sources.

47  derbyPU  INFO   [main] openjpa.Runtime - Starting OpenJPA 0.9.7-incubating-SNAPSHOT

I verified that 0.9.7-incubating-SNAPSHOT and 0.9.8-incubating-SNAPSHOT worked fine.

> query param value issue in select query
> ---------------------------------------
>
>                 Key: OPENJPA-217
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-217
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: jpa, query
>    Affects Versions: 0.9.6
>            Reporter: sharath.h
>            Priority: Minor
>
> Consider a scenario where we have an entity class as shown below:
> class A
> {
>  long id;
> String str1;
> String str2;
> }
> Say for str2 attribute there will be length constraint something like 
> <basic name="str2" >
>           <column name="col2"  length="4"/>        
>  </basic>
> Now say i have a jpql select query as shown below :
> Query q = em.createQuery("select t from A t where t.str2:paramvalue");
> q.setParameter("paramvalue", "23");
> The above query return empty result set even though the records are present in table.
> But when i set the value from "23" to "23  " (i.e. with trailing 2 spaces) it works.
> Can the padding of additional empty spaces be taken care default by jpa itself for select kind of queries.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.