in(prop, query) no longer working

61 views
Skip to first unread message

Mario Ivankovits

unread,
May 6, 2009, 3:28:17 AM5/6/09
to Ebean ORM
Hi!

With the change for the "update updated columns only" feature the
feature Expr.in(prop, Query) seems to no longer work.

The reason is, that, if you are going to select a single field with
inquery.select("key.field") the SqlTreeBuilder.addProperty method will
always add "key" to the list of selected props.
This is to populate any embedded object fully as the "update updated
columns only" feature is not yet capable of dealing with embedded
objects.

It is a little bit hard to find a solution here as even if I manage to
ignore the embedded stuff for such in-queries, the else case in
addProperty will ignore and Id (if p.isId do nothing) then.

Any idea?

Ciao,
Mario

rob bygrave

unread,
May 6, 2009, 7:39:48 AM5/6/09
to eb...@googlegroups.com

Ignoring the embedded beans issue... the fix is to additionally use !subQuery to include the id in the subquery query.


SqlTreeBuilder line 297 becomes:

} else if (!subQuery && p.isId()) {




Now, my quick test using an ID works:

        Query<Product> subQuery = Ebean.createQuery(Product.class)
                        .select("id").where().idEq(4).query();
       
        List<MinCustomer> list = Ebean.find(MinCustomer.class)
            .where().in("id", subQuery).findList();


select c.id, c.name, c.notes
from o_customer c
where  (c.id) in (select p.id  from o_product p  where p.id = ?  )



From: Mario Ivankovits <mario.iv...@gmail.com>
To: Ebean ORM <eb...@googlegroups.com>
Sent: Wednesday, May 6, 2009 7:28:17 PM
Subject: in(prop, query) no longer working

Mario Ivankovits

unread,
May 6, 2009, 12:43:34 PM5/6/09
to Ebean ORM
Hi Rob!

By adding the following to the head of addProperty

private void addProperty(SqlTreeProperties selectProps,
BeanDescriptor<?> desc, OrmQueryProperties queryProps, String
propName) {

if (subQuery) {
BeanProperty p = desc.findBeanProperty(propName);
if (p == null) {
logger.log(Level.SEVERE, "property [" + propName + "]
not found on " + desc
+ " for query - excluding it.");
}
else if (p instanceof BeanPropertyAssoc)
{
int pos = propName.indexOf(".");
if (pos > -1)
{
String name = propName.substring(pos+1);
p = ((BeanPropertyAssoc) p).getTargetDescriptor
().findBeanProperty(name);
}
}

selectProps.add(p);

return;
}

it started to work again. For sure, this is a hack only, but better
than nothing for the moment.

rob bygrave

unread,
May 6, 2009, 5:33:16 PM5/6/09
to eb...@googlegroups.com

Looks like your code change works for embedded properties in the subquery so that is good.

As you say, until embedded beans get full support for 'partial objects' we have to treat "sub queries" a little differently so the code possibly looks a little ugly/hacky but I'm not unhappy with this at this point.

Good stuff.
- Rob.


From: Mario Ivankovits <mario.iv...@gmail.com>
To: Ebean ORM <eb...@googlegroups.com>
Sent: Thursday, May 7, 2009 4:43:34 AM
Subject: Re: in(prop, query) no longer working
Reply all
Reply to author
Forward
0 new messages