码迷,mamicode.com
首页 > Web开发 > 详细

Hibernate定制Tuplizer

时间:2015-04-17 20:11:55      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:

Hibernate定制Tuplizer,使用@Tuplizer注解

 本文转自http://www.521100.net/hibernate-tuplizer.html

   首先,第一步在Hinbernate实体上增加注解@Tuplizer,它有两参数
         1.entityMode 默认pojo
         2.2.impl 自己的Tuplizer实现类,填写完整的类名称 com.woaitech.WiPojoEntityTuplizer

   其次,实现自己的Tuplizer,如下<br />
       public class WiPojoEntityTuplizer extends PojoEntityTuplizer {
           public WiPojoEntityTuplizer(EntityMetamodel entityMetamodel, PersistentClass mappedEntity) {
               super(entityMetamodel, mappedEntity);
             }


            protected Getter buildPropertyGetter(Property mappedProperty, PersistentClass mappedEntity) {
               return mappedProperty.getGetter( mappedEntity.getMappedClass() );
            }


            protected Setter buildPropertySetter(Property mappedProperty, PersistentClass mappedEntity) {
               return mappedProperty.getSetter( mappedEntity.getMappedClass() );
            }
       }
   上面的代码只是简单重写了PojoEntityTulizer的两个方法,他们的作用的是构建属性访问器。那么如果有需要就可以返回自己的属性访问器,来达到定制的目的。
   它的作用如doc上描述一样•extract values from and inject values into such a data structure 
   连接了实体到数据库。

  

Hibernate定制Tuplizer

标签:

原文地址:http://www.cnblogs.com/woaitech/p/4435525.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!