Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
Custom query using inner join across the same table in Service Builder.
Does anybody know if Liferay Service Builder runs fine when has to deal with a custom-sql consisting of an inner join clause across the same table?
(1) Lets suppose we have this custom sql:
select e1.*, e2.* from entity as e1 inner join entity as e2 on e1.id=e2.parentid;
(2) Lets suppose we have this custom finder method too:
public List findMyEntityList() throws SystemException {
Session session = null;
try {
session = openSession();
String sql = ...
SQLQuery queryObject = session.createSQLQuery(sql);
queryObject.setCacheable(false);
queryObject.addEntity("entity1", EntityImpl.class);
queryObject.addEntity("entity2", EntityImpl.class);
QueryPos qPos = QueryPos.getInstance(queryObject);
return (List) QueryUtil.list(queryObject, getDialect(), QueryUtil.ALL_POS, QueryUtil.ALL_POS);
}
catch (Exception e) {
e.printStackTrace();
}
finally {
closeSession(session);
}
return null;
}
(3) And lets suppose this code is the one in charge of reading the
values recovered by the .findMyEntityList()
:
for (Object object : this.myEntityList) {
Object[] objectArray = (Object[]) object;
e1 = (Entity) objectArray[0];
e2 = (Entity) objectArray[1];
...
}
When I check the size of the myEntityList
t's the one
expected. However, when I print the values of both e1 and e2 model
entities, they all are equal among them; it seems that e1 equals e2,
that is, it seems that Service Builder is not able of distingishing
that it has to store two diferent 'Entity' model classes (the one on
the left side on the inner join clause, and the one on the right side).
Any comment or clarification would be appreciate.
Powered by Liferay™