My environment:
Windows XP
JDK 1.6
MySQL, version: 5.0.41-community-nt
MySQL-AB JDBC Driver, version: mysql-connector-java-5.0.7
Hibernate Annotations 3.3.0.GA
Hibernate 3.2.4.sp1
Hibernate EntityManager 3.3.1.GA
The problem:
I have a class User that uses an @Loader annotation for specifying native SQL. The relevant portions are copied below:
@Entity
@Table(name = "users", catalog = "cdd", uniqueConstraints = { @UniqueConstraint(columnNames = { "user_name" }) })
@SQLInsert( sql="INSERT INTO cdd.users (full_name, is_administrator, is_disabled, is_readonly, user_name, user_password ) VALUES ( ?, ?, ?, ?, ?, AES_ENCRYPT(?, 'cdd') )")
@SQLUpdate( sql="UPDATE cdd.users SET full_name=?, is_administrator=?, is_disabled=?, is_readonly = ?, user_name=?, user_password=AES_ENCRYPT(?, 'cdd') WHERE UID=?")
@SQLDelete (sql="DELETE FROM cdd.users where UID = ?")
@SQLDeleteAll (sql="DELETE cdd.users")
@NamedNativeQuery (name = "load_user", query = "SELECT UID, full_name, is_administrator, is_disabled, is_readonly, user_name, AES_DECRYPT(user_password, 'cdd') as user_password FROM cdd.users WHERE UID=?", resultClass=User.class)
@Loader (namedQuery = "load_user")
public class User implements java.io.Serializable {
...
}
I am able to use the named query directly from the EntityManager as:
EntityManager em = EntityManagerHelper.getEntityManager();
Query q = em.createNamedQuery("load_user");
q.setParameter(1, 10);
em.getTransaction().begin();
User u = (User) q.getSingleResult();
However, when I "load" an instance of User by calling:
String queryString = "select model from User model";
List<User> users = getEntityManager().createQuery(queryString).getResultList();
the returned instances of User are populated without using the named query identified by the @Loader annotation. I can verify that easily as the named query is basically intended to descrypt the user passwords from the database.
The relevant log entries are:
...
07/28/2007 04:54:59 INFO AnnotationBinder:398 - Binding entity from annotated class: com.epistemic.cdd.db.User
07/28/2007 04:54:59 INFO QueryBinder:127 - Binding named native query: load_user => SELECT UID, full_name, is_administrator, is_disabled, is_readonly, user_name, AES_DECRYPT(user_password, 'cdd') as user_password FROM cdd.users WHERE UID=?
07/28/2007 04:54:59 INFO EntityBinder:420 - Bind entity com.epistemic.cdd.db.User on table users
...
07/28/2007 04:55:01 DEBUG AbstractEntityPersister:2738 - Static SQL for entity: com.epistemic.cdd.db.User
07/28/2007 04:55:01 DEBUG AbstractEntityPersister:2743 - Version select: select UID from cdd.users where UID =?
07/28/2007 04:55:01 DEBUG AbstractEntityPersister:2746 - Snapshot select: select user_.UID, user_.full_name as full2_18_, user_.is_administrator as is3_18_, user_.is_disabled as is4_18_, user_.is_readonly as is5_18_, user_.user_name as user6_18_, user_.user_password as user7_18_ from cdd.users user_ where user_.UID=?
07/28/2007 04:55:01 DEBUG AbstractEntityPersister:2749 - Insert 0: INSERT INTO cdd.users (full_name, is_administrator, is_disabled, is_readonly, user_name, user_password ) VALUES ( ?, ?, ?, ?, ?, AES_ENCRYPT(?, 'cdd') )
07/28/2007 04:55:01 DEBUG AbstractEntityPersister:2750 - Update 0: UPDATE cdd.users SET full_name=?, is_administrator=?, is_disabled=?, is_readonly = ?, user_name=?, user_password=AES_ENCRYPT(?, 'cdd') WHERE UID=?
07/28/2007 04:55:01 DEBUG AbstractEntityPersister:2751 - Delete 0: DELETE cdd.users
07/28/2007 04:55:01 DEBUG AbstractEntityPersister:2755 - Identity insert: INSERT INTO cdd.users (full_name, is_administrator, is_disabled, is_readonly, user_name, user_password ) VALUES ( ?, ?, ?, ?, ?, AES_ENCRYPT(?, 'cdd') )
...
07/28/2007 04:55:01 DEBUG SQL:401 -
select
user0_.UID as UID18_,
user0_.full_name as full2_18_,
user0_.is_administrator as is3_18_,
user0_.is_disabled as is4_18_,
user0_.is_readonly as is5_18_,
user0_.user_name as user6_18_,
user0_.user_password as user7_18_
from
cdd.users user0_
Hibernate:
select
user0_.UID as UID18_,
user0_.full_name as full2_18_,
user0_.is_administrator as is3_18_,
user0_.is_disabled as is4_18_,
user0_.is_readonly as is5_18_,
user0_.user_name as user6_18_,
user0_.user_password as user7_18_
from
cdd.users user0_
07/28/2007 04:55:02 DEBUG AbstractEntityPersister:2031 - Hydrating entity: [com.epistemic.cdd.db.User#1]
Is this a bug?
|