0

My problem statement is :- I want to call a stored procedure in hibernate and i want to map each column to class attributes after performing certain operations on the column returned by the stored procedure.. As any hibernate query return a list of object instead of resultset.. so how can i do it in hibernate... I know in spring we can do it using jdbcTemplate Map row concept easily but I want to use Hibernate only..

More details can be found out in my prev question:- Alternative to NamedParameterJDBC template row mapper in Hibernate

4

1 回答 1

1

有时我们有一个类,我们想根据查询返回的数据填充数据。该类是一个简单的 POJO 而不是 Hibernate 实体,因此 Hibernate 不会识别该类。这可以通过使用 Transformers 在 Hibernate 中完成。

(UserActivityStat)hibernateSession.createQuery("select count(*) as totalPhotos from Photo p where p.user = :user").setResultTransformer(Transformers.aliasToBean(UserActivityStat.class)).uniqueResult();

在上面的示例中,totalPhotos 是 UserActivityStat 类的属性,它不是 HibernateEntity。使用变压器,您可以实现您的结果。

于 2013-10-21T06:08:35.493 回答