What is your favourite Hibernate trick?
+3
A:
In a webapp:
using a Filter to start and terminate a transaction
defining a view to accommodate tomcat's jdbc authentification:
<database-object>
<!-- rolemap view -->
<create>
CREATE VIEW rolemap(username,role) AS
SELECT u.username,ur.role_code
FROM users as u, users_roles as ur
WHERE ur.user_id=u.id
</create>
<drop>DROP VIEW IF EXISTS rolemap</drop>
</database-object>
casting a query result into a typed list:
Session pm = Factory.getSession();
Query qry = pm.createQuery("from Laboratory");
@SuppressWarnings("unchecked")
List<Laboratory> labs = (List<Laboratory>)qry.list();
for (Laboratory lab: labs) {
...
}
Maurice Perry
2009-03-16 12:57:44