openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Norbert Rieger" <nrie...@lplusr.de>
Subject JPQL Query with embedded object
Date Fri, 07 Nov 2008 09:25:12 GMT
Hi,

 

I'm working with Apache Geronimo 2.1.3. 

 

I've an embedded object in my entity class.

 

Making the entity persistent is no problem, the embedded object works fine,
but when this object is part of a query's where clause it does not work,

it's converted to "WHERE (1 <> 1)" which (IMHO) is never true.

 

This are my classes:

 

//
----------------------------------------------------------------------------

      @Embeddable

      public static class BaseId implements Serializable {

 

            private static final long serialVersionUID =
7143689378031391420L;

            

            protected String val ;

 

        ....

    }

 

//
----------------------------------------------------------------------------

      @Embeddable

      @AttributeOverride(name="val", 

                         column=@Column(name="ident")) 

      public static class MyIdent extends BaseId {

 

            private static final long serialVersionUID =
-492669352494445761L;

      

            public MyIdent () {

               super();

            }

            public MyIdent (String ident) {

               super(ident);

            }

            

        ....

    }

 

//
----------------------------------------------------------------------------

    @Entity

    public class Owner implements OwnerIf, Serializable {

      

      private static final long serialVersionUID = 3370703487710772895L;

      

        @Id

        private long pKey;

 

        @Embedded

        private MyIdent ident;

 

        

//
----------------------------------------------------------------------------

This is the Query:

 

    MyIdent ownerIdent = new MyIdent ("TEST") ;

    owner = (Owner) em.createQuery("SELECT o FROM Owner o WHERE o.ident =
:ident")

                      .setParameter ("ident", ownerIdent)

                      .getSingleResult () ;

 

 

And this is the trace:        

945980  PersUnit  TRACE  [ejbd 8] openjpa.Query - Executing query: [SELECT o
FROM Owner o WHERE o.ident = ?1] with parameters: {1=TEST}

947417  PersUnit  TRACE  [ejbd 8] openjpa.jdbc.SQL - <t 17090750, conn
153947> executing prepstmnt 21779345 SELECT t0.pKey, t0.genDate, t0.ident,
t0.mmd_pkey, t0.smd_pkey FROM Owner t0 WHERE (1 <> 1)

 

//
----------------------------------------------------------------------------

If I use the "val" field of MyIdent, the query works. But I think this is
not was it is supposed to be or is it ? If running on JBoss/Hibernate it
does not work.

 

    MyIdent ownerIdent = new MyIdent ("TEST") ;

    owner = (Owner) em.createQuery("SELECT o FROM Owner o WHERE o.ident.val
= :val")

                      .setParameter ("val", ownerIdent.getValue ())

                      .getSingleResult () ;

 

 

And this is the trace: 

179844  PersUnit  TRACE  [ejbd 3] openjpa.Query - Executing query: [SELECT o
FROM Owner o WHERE o.ident.val = :val] with parameters: {val=TEST}

181235  PersUnit  TRACE  [ejbd 3] openjpa.jdbc.SQL - <t 25015360, conn
14421085> executing prepstmnt 15327648 SELECT t0.pKey, t0.genDate, t0.ident,
t0.mmd_pkey, t0.smd_pkey FROM Owner t0 WHERE (t0.ident = ?) [params=(String)
TEST]

 

//
----------------------------------------------------------------------------

What's wrong with my definitions/query ? How do I use an embedded object in
a query ?

 

Thanks a lot for your answers.

 

NR

 


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message