I've been working on an app built on top of JBoss AS 4.0.3sp1/EJB3rc3. I'm in the process of converting it to work with JBoss AS 4.0.4.GA/EJB3rc7.
Most of the changes required have been easily handled thanks to documentation, wiki, and forum posts. Big thanks to all who have contributed!
I am currently stuck on using HibernateQuery instead of the EJB Query and could use some help or direction.
In a number of places, we've preferred to use the HibernateQuery because is returns null for a non-existent entity, instead of throwing an exception (EntityNotFoundException previously, now NoResultException).
We would do this as follows:
Code:
public User getUserByEmail(String email) {
HibernateQuery hq = (HibernateQuery) em.createQuery(
"select emailAddress.user from EmailAddress as emailAddress where emailAddress.email = ?1")
.setParameter(1, email);
return (User) hq.getHibernateQuery().uniqueResult();
}
However, org.hibernate.ejb.HibernateQuery is no longer available.
I tried the following, but this produces a ClassCastException:
Code:
public User getUserByEmail(String email) {
org.hibernate.Query hq = (org.hibernate.Query) em
.createQuery(
"select emailAddress.user from EmailAddress as emailAddress where emailAddress.email = ?1")
.setParameter(1, email);
return (User) hq.uniqueResult();
}
Can someone point me to the proper way to use org.hibernate.Query? Or better yet, point me to a recommended approach to getting the behavior we're after (a single result of null when an entity is not found without having an exception thrown)? I'm trying to avoid the processing of unnecessary throwables.
Thanks for the help and/or guidance,
Jonn