| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| 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 |
|
#2
| |||
| |||
| The workaround can be the following: MyIdent ownerIdent = new MyIdent ("TEST") ; Owner owner = (Owner) em.createQuery("SELECT o FROM Owner o WHERE o.ident.val =:ident") .setParameter ("ident", ownerIdent.getVal()) .getSingleResult () ; nrieger wrote: > > 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 > > > > > -- View this message in context: http://n2.nabble.com/JPQL-Query-with...5p1471423.html Sent from the OpenJPA Users mailing list archive at Nabble.com. |
|
#3
| |||
| |||
| Hi, yes, I think this will work for openJPA, I've tried this already. But it's a workaround (valid only for openJPA ?) with some disadvantages: - maybe this is not portable (I'm sorry for that, but our application needs to run on Apache Geronimo and at least on JBoss without openJPA) - I don't what to have an implementation detail like a protected field ("val") in the query, I think this was not a goal of JPA (I thought we should think about object and not of SQL tables and columns) - each query has to be changed e.g. if the "val" field gets renamed to "value" (which is very error prone) Is this a known bug in openJPA (which delivers with Geronimo 2.1.3) or am I wrong with my query/understanding of JPA's query language ? Thanks a lot for your answers. NR -----Ursprüngliche Nachricht----- Von: Pinaki Poddar [mailto poddar-1oDqGaOF3Lkdnm+yROfE0A@public.gmane.org] Gesendet: Freitag, 7. November 2008 21:52 An: users-8spYzHhHo/jWgOoZo4XcuR2eb7JE58TQ@public.gmane.org Betreff: Re: JPQL Query with embedded object The workaround can be the following: MyIdent ownerIdent = new MyIdent ("TEST") ; Owner owner = (Owner) em.createQuery("SELECT o FROM Owner o WHERE o.ident.val =:ident") .setParameter ("ident", ownerIdent.getVal()) .getSingleResult () ; nrieger wrote: > > 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 > > > > > -- View this message in context: http://n2.nabble.com/JPQL-Query-with...5p1471423.html Sent from the OpenJPA Users mailing list archive at Nabble.com. |
|
#4
| |||
| |||
| So you're saying is that OpenJPA does not support querying of Embedded objects, but it does support querying fields of embedded objects? So, do you think this could be corrected in openjpa code? I would suggest that we might want to wade through code and maybe submit a patch.. could you point us to where to start looking to maybe include this functionality? Pinaki Poddar wrote: > The workaround can be the following: > MyIdent ownerIdent = new MyIdent ("TEST") ; > Owner owner = (Owner) em.createQuery("SELECT o FROM Owner o WHERE > o.ident.val =:ident") > .setParameter ("ident", > ownerIdent.getVal()) > .getSingleResult () ; > > > > > nrieger wrote: >> 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 >> >> >> >> >> > |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.