michael wrote:
the id property is ignored in example queries. Just add a normal criterion.
I strongly feel this is a bug. I fervently love the QBE functionality, but this was completely unexpected when I encountered it yesterday.
Furthermore, are association classes also ignored in QBE? That is, if a child has an association to its parent, I have noticed that if you set only the parent, and do a QBE, hibernate ignores it as well.
This works:
Code:
public void testSearchOrders() throws Exception {
Session session = sf.openSession();
// Account resultAcct = (Account) session.get(Account.class, new Long(1001084));
//Order order = new Order();
//order.setAccount(resultAcct);
List orderResults = session.createCriteria(Order.class).add(Expression.eq("account.accountId", new Long(1001084))).list();
assertTrue(orderResults.size() > 0);
for (Iterator iter = orderResults.iterator(); iter.hasNext();) {
Order order2 = (Order) iter.next();
assertTrue(order2.getAccount().getAccountId().equals(resultAcct.getAccountId()));
}
session.close();
}
This does not work:
Code:
public void testSearchOrders() throws Exception {
Session session = sf.openSession();
Account account = new Account();
// DOES NOT WORK account.setAccountId(new Long(1001084));
account.setAccountName("some valid name");
List acctRes = session.createCriteria(Account.class).add(Example.create(account)).list();
Account resultAcct = (Account)acctRes.get(0);
Order order = new Order();
order.setAccount(resultAcct);
List orderResults = session.createCriteria(Order.class).add(Example.create(order)).list();
for (Iterator iter = orderResults.iterator(); iter.hasNext();) {
Order order2 = (Order) iter.next();
// assertion fails
assertTrue(order2.getAccount().getAccountId().equals(resultAcct.getAccountId()));
}
session.close();
}
Account mapping snippet ()
Code:
<!-- bi-directional one-to-many association to Order -->
<set
name="orders"
lazy="false"
inverse="true"
cascade="all"
>
<key>
<column name="ACCOUNT_ID" />
</key>
<one-to-many
class="com.cybera.seneca.persistence.Order"
/>
</set>
Order mapping snippet (perhaps the problem is in here?)
Code:
<!-- associations -->
<!-- bi-directional many-to-one association to Account -->
<many-to-one
name="account"
class="com.cybera.seneca.persistence.Account"
not-null="true"
>
<column name="ACCOUNT_ID" />
</many-to-one>
thanks in advance. I'm using hibernate 2.1.4.