利用hibernatedoclet生成hbm文件

来源:互联网 发布:淘宝旗舰店转让 编辑:程序博客网 时间:2024/05/16 15:23

利用hibernatedoclet生成hbm文件遇到的问题20

现在项目中用ant hibernatedoclet自动生成pojo的hbm文件,生成简单的pojo很正常。如果一个类的继承有两层以上的话,只能生成父类的字段,祖父及以上类的字段无论如何都生成不了。

如ExamQuestion继承了Question,Question是一个抽象类,继承自BusBaseObject,在用ant hibernatedoclet生成hbm文件时,只能生产Question类中的字段配置,没有生成BusBaseObject中的字段配置。但是对于其它直接继承BusBaseObject的类,是可以生成BusBaseObject中的字段配置到hbm文件中的。

不知道各位有没有遇到过类似问题,有没有解决办法。

 

这是类图:

 

build.xml配置:

Xml代码  收藏代码
  1. <target name="hibernatedoclet" depends="prepare" unless="hibernatedoclet.unnecessary"  
  2.         description="Generate Hibernate mapping files">  
  3.         <taskdef name="hibernatedoclet"  
  4.             classname="xdoclet.modules.hibernate.HibernateDocletTask"  
  5.             classpathref="xdoclet.classpath"/>  
  6.               
  7.         <echo>generate hibernate files</echo>  
  8.         <mkdir dir="src/java/${module.name}"/>  
  9.         <if>  
  10.             <not><equals arg1="${module.name}" arg2="commons"/></not>  
  11.             <then>  
  12.                 <hibernatedoclet destdir="${build.dir}/hbm"  
  13.                     excludedtags="@version,@author" addedtags="@xdoclet-generated at ${TODAY}"  
  14.                     force="${xdoclet.force}">  
  15.                     <fileset dir="${src}" includes="**/model/*.java"/>  
  16.                     <fileset dir="${src}/${module.name}" includes="**/model/*.java"/>  
  17.                     <hibernate validatexml="true" version="3.0"/>  
  18.                 </hibernatedoclet>          
  19.             </then>  
  20.         </if>  
  21.     </target>  
 

 

生成的hbm文件如下:

Hbm代码  收藏代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2.   
  3. <!DOCTYPE hibernate-mapping PUBLIC  
  4.     "-//Hibernate/Hibernate Mapping DTD 3.0//EN"   
  5.     "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">  
  6.   
  7. <hibernate-mapping  
  8.   
  9. >  
  10.   
  11.     <class  
  12.             name="com.ed365.exam.model.ExamQuestion"  
  13.             table="EXAM_QUESTION"  
  14.     >  
  15.   
  16.     <id  
  17.         name="examQuestionId"  
  18.             column="EXAM_QUESTION_ID"  
  19.                 type="string"  
  20.             length="32"  
  21.     >  
  22.   
  23.     <!-- The generator-class attribute of @hibernate.id is deprecated, use the @hibernate.generator tag instead -->  
  24.     <generator class="uuid">  
  25.   
  26.     </generator>  
  27.   
  28.     </id>  
  29.   
  30.         <property  
  31.             name="grade"  
  32.                     type="string"  
  33.                     column="GRADE"  
  34.                 length="32"  
  35.                 not-null="true"  
  36.         >  
  37.   
  38.         </property>  
  39.   
  40.         <property  
  41.             name="subject"  
  42.                     type="string"  
  43.                     column="SUBJECT"  
  44.                 length="32"  
  45.                 not-null="true"  
  46.         >  
  47.   
  48.         </property>  
  49.   
  50.         <property  
  51.             name="section"  
  52.                     type="string"  
  53.                     column="SECTION"  
  54.                 length="32"  
  55.                 not-null="true"  
  56.         >  
  57.   
  58.         </property>  
  59.   
  60.         <property  
  61.             name="contentType"  
  62.                     type="string"  
  63.                     column="CONTENT_TYPE"  
  64.                 length="32"  
  65.                 not-null="true"  
  66.         >  
  67.   
  68.         </property>  
  69.   
  70.         <property  
  71.             name="questionKeyWords"  
  72.                     type="string"  
  73.                     column="QUESTION_KEYWORDS"  
  74.                 length="1000"  
  75.         >  
  76.   
  77.         </property>  
  78.   
  79.         <property  
  80.             name="difficulty"  
  81.                     type="string"  
  82.                     column="DIFFICULTY"  
  83.                 length="32"  
  84.                 not-null="true"  
  85.         >  
  86.   
  87.         </property>  
  88.   
  89.         <property  
  90.             name="discrimination"  
  91.                     type="string"  
  92.                     column="DISCRIMINATION"  
  93.                 length="32"  
  94.                 not-null="true"  
  95.         >  
  96.   
  97.         </property>  
  98.   
  99.         <property  
  100.             name="cognition"  
  101.                     type="string"  
  102.                     column="COGNITION"  
  103.                 length="32"  
  104.                 not-null="true"  
  105.         >  
  106.   
  107.         </property>  
  108.   
  109.         <property  
  110.             name="claim"  
  111.                     type="string"  
  112.                     column="CLAIM"  
  113.                 length="1000"  
  114.         >  
  115.   
  116.         </property>  
  117.   
  118.         <property  
  119.             name="reviser"  
  120.                     type="string"  
  121.                     column="REVISER"  
  122.                 length="32"  
  123.         >  
  124.   
  125.         </property>  
  126.   
  127.         <property  
  128.             name="reviseDate"  
  129.                     type="date"  
  130.                     column="REVISE_DATE"  
  131.         >  
  132.   
  133.         </property>  
  134.   
  135.         <property  
  136.             name="parentId"  
  137.                     type="string"  
  138.                     column="PARENT_ID"  
  139.                 length="32"  
  140.         >  
  141.   
  142.         </property>  
  143.   
  144.         <property  
  145.             name="issueScope"  
  146.                     type="string"  
  147.                     column="ISSUE_SCOPE"  
  148.                 length="32"  
  149.         >  
  150.   
  151.         </property>  
  152.   
  153.         <property  
  154.             name="questionType"  
  155.                     type="string"  
  156.                     column="QUESTION_TYPE"  
  157.                 length="32"  
  158.                 not-null="true"  
  159.         >  
  160.   
  161.         </property>  
  162.   
  163.         <property  
  164.             name="questionContent"  
  165.                     type="text"  
  166.                     column="QUESTION_CONTENT"  
  167.                 not-null="true"  
  168.         >  
  169.   
  170.         </property>  
  171.   
  172.         <property  
  173.             name="attachmentId"  
  174.                     type="string"  
  175.                     column="ATTACHMENT_ID"  
  176.                 length="2000"  
  177.         >  
  178.   
  179.         </property>  
  180.   
  181.     </class>      
  182.   
  183. </hibernate-mapping>  
 

 


问题补充:
因为要做自动化部署,不想每次用手动去改hbm文件或者手动去重新生成hbm文件。 
问题补充:
我们开发是用eclipse部署,但是发布和每日构建是用ant自动编译的,目前build.xml已经写了很多代码,如果放弃不用,还得重头再来,而且用eclipse做发布和每日构建并不是很好的选择。
0

利用hibernatedoclet生成hbm文件遇到的问题20

现在项目中用ant hibernatedoclet自动生成pojo的hbm文件,生成简单的pojo很正常。如果一个类的继承有两层以上的话,只能生成父类的字段,祖父及以上类的字段无论如何都生成不了。

如ExamQuestion继承了Question,Question是一个抽象类,继承自BusBaseObject,在用ant hibernatedoclet生成hbm文件时,只能生产Question类中的字段配置,没有生成BusBaseObject中的字段配置。但是对于其它直接继承BusBaseObject的类,是可以生成BusBaseObject中的字段配置到hbm文件中的。

不知道各位有没有遇到过类似问题,有没有解决办法。

 

这是类图:

 

build.xml配置:

Xml代码  收藏代码
  1. <target name="hibernatedoclet" depends="prepare" unless="hibernatedoclet.unnecessary"  
  2.         description="Generate Hibernate mapping files">  
  3.         <taskdef name="hibernatedoclet"  
  4.             classname="xdoclet.modules.hibernate.HibernateDocletTask"  
  5.             classpathref="xdoclet.classpath"/>  
  6.               
  7.         <echo>generate hibernate files</echo>  
  8.         <mkdir dir="src/java/${module.name}"/>  
  9.         <if>  
  10.             <not><equals arg1="${module.name}" arg2="commons"/></not>  
  11.             <then>  
  12.                 <hibernatedoclet destdir="${build.dir}/hbm"  
  13.                     excludedtags="@version,@author" addedtags="@xdoclet-generated at ${TODAY}"  
  14.                     force="${xdoclet.force}">  
  15.                     <fileset dir="${src}" includes="**/model/*.java"/>  
  16.                     <fileset dir="${src}/${module.name}" includes="**/model/*.java"/>  
  17.                     <hibernate validatexml="true" version="3.0"/>  
  18.                 </hibernatedoclet>          
  19.             </then>  
  20.         </if>  
  21.     </target>  
 

 

生成的hbm文件如下:

Hbm代码  收藏代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2.   
  3. <!DOCTYPE hibernate-mapping PUBLIC  
  4.     "-//Hibernate/Hibernate Mapping DTD 3.0//EN"   
  5.     "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">  
  6.   
  7. <hibernate-mapping  
  8.   
  9. >  
  10.   
  11.     <class  
  12.             name="com.ed365.exam.model.ExamQuestion"  
  13.             table="EXAM_QUESTION"  
  14.     >  
  15.   
  16.     <id  
  17.         name="examQuestionId"  
  18.             column="EXAM_QUESTION_ID"  
  19.                 type="string"  
  20.             length="32"  
  21.     >  
  22.   
  23.     <!-- The generator-class attribute of @hibernate.id is deprecated, use the @hibernate.generator tag instead -->  
  24.     <generator class="uuid">  
  25.   
  26.     </generator>  
  27.   
  28.     </id>  
  29.   
  30.         <property  
  31.             name="grade"  
  32.                     type="string"  
  33.                     column="GRADE"  
  34.                 length="32"  
  35.                 not-null="true"  
  36.         >  
  37.   
  38.         </property>  
  39.   
  40.         <property  
  41.             name="subject"  
  42.                     type="string"  
  43.                     column="SUBJECT"  
  44.                 length="32"  
  45.                 not-null="true"  
  46.         >  
  47.   
  48.         </property>  
  49.   
  50.         <property  
  51.             name="section"  
  52.                     type="string"  
  53.                     column="SECTION"  
  54.                 length="32"  
  55.                 not-null="true"  
  56.         >  
  57.   
  58.         </property>  
  59.   
  60.         <property  
  61.             name="contentType"  
  62.                     type="string"  
  63.                     column="CONTENT_TYPE"  
  64.                 length="32"  
  65.                 not-null="true"  
  66.         >  
  67.   
  68.         </property>  
  69.   
  70.         <property  
  71.             name="questionKeyWords"  
  72.                     type="string"  
  73.                     column="QUESTION_KEYWORDS"  
  74.                 length="1000"  
  75.         >  
  76.   
  77.         </property>  
  78.   
  79.         <property  
  80.             name="difficulty"  
  81.                     type="string"  
  82.                     column="DIFFICULTY"  
  83.                 length="32"  
  84.                 not-null="true"  
  85.         >  
  86.   
  87.         </property>  
  88.   
  89.         <property  
  90.             name="discrimination"  
  91.                     type="string"  
  92.                     column="DISCRIMINATION"  
  93.                 length="32"  
  94.                 not-null="true"  
  95.         >  
  96.   
  97.         </property>  
  98.   
  99.         <property  
  100.             name="cognition"  
  101.                     type="string"  
  102.                     column="COGNITION"  
  103.                 length="32"  
  104.                 not-null="true"  
  105.         >  
  106.   
  107.         </property>  
  108.   
  109.         <property  
  110.             name="claim"  
  111.                     type="string"  
  112.                     column="CLAIM"  
  113.                 length="1000"  
  114.         >  
  115.   
  116.         </property>  
  117.   
  118.         <property  
  119.             name="reviser"  
  120.                     type="string"  
  121.                     column="REVISER"  
  122.                 length="32"  
  123.         >  
  124.   
  125.         </property>  
  126.   
  127.         <property  
  128.             name="reviseDate"  
  129.                     type="date"  
  130.                     column="REVISE_DATE"  
  131.         >  
  132.   
  133.         </property>  
  134.   
  135.         <property  
  136.             name="parentId"  
  137.                     type="string"  
  138.                     column="PARENT_ID"  
  139.                 length="32"  
  140.         >  
  141.   
  142.         </property>  
  143.   
  144.         <property  
  145.             name="issueScope"  
  146.                     type="string"  
  147.                     column="ISSUE_SCOPE"  
  148.                 length="32"  
  149.         >  
  150.   
  151.         </property>  
  152.   
  153.         <property  
  154.             name="questionType"  
  155.                     type="string"  
  156.                     column="QUESTION_TYPE"  
  157.                 length="32"  
  158.                 not-null="true"  
  159.         >  
  160.   
  161.         </property>  
  162.   
  163.         <property  
  164.             name="questionContent"  
  165.                     type="text"  
  166.                     column="QUESTION_CONTENT"  
  167.                 not-null="true"  
  168.         >  
  169.   
  170.         </property>  
  171.   
  172.         <property  
  173.             name="attachmentId"  
  174.                     type="string"  
  175.                     column="ATTACHMENT_ID"  
  176.                 length="2000"  
  177.         >  
  178.   
  179.         </property>  
  180.   
  181.     </class>      
  182.   
  183. </hibernate-mapping>  
 

 


问题补充:
因为要做自动化部署,不想每次用手动去改hbm文件或者手动去重新生成hbm文件。 
问题补充:
我们开发是用eclipse部署,但是发布和每日构建是用ant自动编译的,目前build.xml已经写了很多代码,如果放弃不用,还得重头再来,而且用eclipse做发布和每日构建并不是很好的选择。
0 0