MyEclipse hibernate Use custom templates 总结

MyEclipse hibernate Use custom templates 总结

首先,在MyEclipse安装目录        myeclipse/eclipse/plugins/com.genuitec.myeclipse.doc_5.5.0/html/quickstarts/hibernate(myeclipse5.5)

下找到myeclipse_templates_5.5GA.zip

复制到一个地方解压。读一下里面的readme.txt

MyEclipse Reverse-Engineering Templates

 

Version: 5.5GA

Minimum required MyEclipse version: 5.5GA

 

Using custom templates with the MyEclipse Reverse-Engineering Process:

 

1) Unzip this archive into a convenient location. We recommend using a project

   in your Eclipse workspace.

 

2) Edit the velocity templates you wish to customize.

  

Note: POJO templates are present in the pojo folder

      DAO template in the dao folder

      HBM templates in the hbm folder

  

3) Optional: Though not necessary, it is recommended that you delete the

   velocity templates you do not plan to customize. This will prevent future

   confusion over which templates are being processed by MyEclipse.

 

4) Invoke the JPA/EJB3/Hibernate Reverse-Engineering wizard and select

   "Use custom templates". Manually enter or click the browse button to select the

   myeclipse_templates_5.5GA folder.

  

   Warning: Do *not* select the dao, hbm or pojo folder, please select the

            parent myeclipse_templates_5.5GA folder only.

  

During the code generation process, MyEclipse gives precedence to user

defined templates by searching the custom template location prior to

consulting the internal templates shipped with MyEclipse.

 

  

   MyEclipse反向工程模板 

版本: 5.5GA 
最低要求MyEclipse版本: 5.5GA 

使用自定义模板的MyEclipse逆向工程过程: 

1
)解压缩这个档案到一个方便的位置。我们建议在您的Eclipse工程文件夹下使用一个新的项目  

2
)编辑velocity模板根据你的要求。 
    
注:POJO的模板在pojo 文件夹中。
      DAO
的模板在dao文件夹中。      

HBM的模板在hbm文件夹中。    
3
)可选:虽然没有必要,建议您删除 你不打算定制velocity模板。这将防止未来 MyEclipse处理时的模板混乱。
 
4
)调用JPA/EJB3/Hibernate逆向工程向导,并选择 使用自定义模板。手动输入或点击浏览按钮来选择 myeclipse_templates_5.5GA文件夹路径。 
    
   
警告:请不要选择道,dao, hbm pojo文件夹,请选择上一级myeclipse_templates_5.5GA文件夹。 
    
在代码生成过程中, MyEclipse优先考虑用户定义的模板,然后才是查找MyEclipse内部模板。 

 

 

我只是修改了一下daohome.vm文件,在里面增加了一删除的方法。

Velocity 代码:

 

    public int deleteByProperty(String propertyName, Object value) {

      // log.debug("finding ${declarationName} instance with property: " + propertyName + ", value: " + value);

       $pojo.importType("org.hibernate.Transaction")  ts = null;

      int dels = 0;

      try {

         String queryString = "delete from ${declarationName} as model where model."

                             + propertyName + "= ?";

#if($hibernateDaoSupport)

         return ${currSession}.find(queryString, value);

#else

         $pojo.importType("org.hibernate.Query") queryObject = ${currSession}.createQuery(queryString);

         queryObject.setParameter(0, value);

               dels = queryObject.executeUpdate();

               ts.commit();

        #end

      } catch (RuntimeException re) {

         if (ts!=null) ts.rollback();

        // log.error("find by property name failed", re);

         throw re;

      }

        return dels;

}

 

 

生成的java代码:

public int deleteByProperty(String propertyName, Object value) {

       // log.debug("finding Archive instance with property: " + propertyName +

       // ", value: " + value);

       Transaction ts = null;

       int dels = 0;

       try {

           String queryString = "delete from House as model where model."

                  + propertyName + "= ?";

           Query queryObject = getSession().createQuery(queryString);

           queryObject.setParameter(0, value);

           dels = queryObject.executeUpdate();

           ts.commit();

       } catch (RuntimeException re) {

           if (ts != null)

              ts.rollback();

           // log.error("find by property name failed", re);

           throw re;

       }

       return dels;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

分布式编程

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值