Are you not showing us the transaction in your code snippet or do you use CMT? The behavior you observed is normal. Hibernate waits as long as possible to execute the SQL insert statement unless you explicitly commit a transaction or execute a method like flush() on the session.
Try this code:
Code:
Asset asset = new Asset();
asset.setAttribute("abc");
Transaction tx = session.beginTransaction()
session.save(asset);
tx.commit();
String hql = "from Asset as asset where asset.attribute=?";
List assets = session.createQuery(hql).setParameters(new String[] { "abc" }, new Type[] { new StringType() }).list();
Iterator it = assets.iterator();
if (it.hasNext()) {
Asset a = (Asset)it.next();
System.out.println(a.getAttribute());
} else {
throw new IllegalStateException("no data");
}
Grant