zoukankan      html  css  js  c++  java
  • 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;

    }

  • 相关阅读:
    VS中注释的使用
    VS2010中:error C2471: 无法更新程序数据库
    VS2010 MFC中在对话框上添加工具栏以及工具栏提示信息并改变图标支持256色
    CToolBar与CToolBarCtrl以及CStatusBar 与CStatusBarCtrl的区别
    error C2664: “wcscpy”: 不能将参数 1 从“LPSTR”转换为“wchar_t *”
    VS2010 MFC中的Picture控件显示图像
    VS2010 MFC中屏蔽ESC和ENTER键关闭对话框的方法
    MFC中CImageList(图形列表控件)、CTreeCtrl(树形列表控件)的简单用法
    窗口类、窗口类对象与窗口 三者之间关系——孙鑫<VC++深入详解>
    VS2010 MFC中改变static字体颜色、大小、背景颜色(自定义类),及手动关联变量的方法
  • 原文地址:https://www.cnblogs.com/daichangya/p/12960192.html
Copyright © 2011-2022 走看看