使用XDoclet2+Ant实现Hibernate3的pojoxmldb代码相互转换Word文档格式.docx

上传人:b****5 文档编号:8401197 上传时间:2023-05-11 格式:DOCX 页数:8 大小:18.49KB
下载 相关 举报
使用XDoclet2+Ant实现Hibernate3的pojoxmldb代码相互转换Word文档格式.docx_第1页
第1页 / 共8页
使用XDoclet2+Ant实现Hibernate3的pojoxmldb代码相互转换Word文档格式.docx_第2页
第2页 / 共8页
使用XDoclet2+Ant实现Hibernate3的pojoxmldb代码相互转换Word文档格式.docx_第3页
第3页 / 共8页
使用XDoclet2+Ant实现Hibernate3的pojoxmldb代码相互转换Word文档格式.docx_第4页
第4页 / 共8页
使用XDoclet2+Ant实现Hibernate3的pojoxmldb代码相互转换Word文档格式.docx_第5页
第5页 / 共8页
使用XDoclet2+Ant实现Hibernate3的pojoxmldb代码相互转换Word文档格式.docx_第6页
第6页 / 共8页
使用XDoclet2+Ant实现Hibernate3的pojoxmldb代码相互转换Word文档格式.docx_第7页
第7页 / 共8页
使用XDoclet2+Ant实现Hibernate3的pojoxmldb代码相互转换Word文档格式.docx_第8页
第8页 / 共8页
亲,该文档总共8页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

使用XDoclet2+Ant实现Hibernate3的pojoxmldb代码相互转换Word文档格式.docx

《使用XDoclet2+Ant实现Hibernate3的pojoxmldb代码相互转换Word文档格式.docx》由会员分享,可在线阅读,更多相关《使用XDoclet2+Ant实现Hibernate3的pojoxmldb代码相互转换Word文档格式.docx(8页珍藏版)》请在冰点文库上搜索。

使用XDoclet2+Ant实现Hibernate3的pojoxmldb代码相互转换Word文档格式.docx

5<

propertyname="

xdoclet.plugin.install.dir"

value="

./lib/xdoclet"

/>

6<

--待处理项目的src目录-->

7<

src.dir"

./src"

8<

--待处理项目的根目录-->

9<

prj.dir"

./"

10

11<

--include进来xdoclet所有jar包-->

12<

pathid="

xdoclet.task.classpath"

description="

xdoclet的所有jar"

13<

filesetdir="

${xdoclet.plugin.install.dir}"

14<

includename="

**/*.jar"

15<

/fileset>

16<

/path>

17<

--include进来待处理项目的所有jar包,意在使用hibernate相关的jar包-->

18<

prj.jar"

项目目录下的所有jar"

19<

${prj.dir}"

20<

21<

22<

23<

--

24继承上2个目录,同时需要把pojo编译好的class文件包含进来。

25这里定义需要留意,很容易掉入到ant的bug陷阱里去。

26详细可参照

27-->

28<

runtime.path"

SchemaExport用的jar和class文件"

29<

pathrefid="

30<

31<

pathelementlocation="

${prj.dir}/build/classes"

32<

33

34<

35xdoclet只在判断未存在hbm.xml的情况下才会生成,已存在的话则不会自动覆盖。

36所以定义一个清空已存在的hbm.xml文件任务。

37-->

38<

targetname="

clean"

清空已有的hbm.xml"

39<

echomessage="

40<

deletedir="

src"

41<

**/po/*.hbm.xml"

42<

/delete>

43<

/target>

44

45<

--根据pojo生成hbm.xml,注意一下pojo的路径即可-->

46<

xdoclet2hbm"

根据pojo生成hbm.xml"

depends="

47<

48<

taskdefname="

xdoclet"

classname="

org.xdoclet.ant.XDocletTask"

classpathref="

49<

xdocletencoding="

50<

${src.dir}"

51<

**/po/*.java"

52<

53<

componentclassname="

org.xdoclet.plugin.hibernate.HibernateMappingPlugin"

destdir="

${basedir}/${src.dir}"

version="

3.0"

54<

/xdoclet>

55<

56

57<

--根据hibernate.cfg.xml文件生成pojo-->

58<

hbm2java"

根据hbm.xml文件生成pojo"

59<

60<

org.hibernate.tool.ant.HibernateToolTask"

61<

hbm2javadestdir="

62<

configurationconfigurationfile="

${src.dir}/hibernate.cfg.xml"

63<

hbm2java/>

64<

/hbm2java>

65<

66

67<

68生成数据库环境的任务。

69这个可能并不常用,使用org.hibernate.tool.hbm2ddl.SchemaExport编写一个JUnittest可以更方便的连搭环境带造数据。

70-->

71<

SchemaExport"

根据hibernate.cfg.xml生成数据库环境"

72<

73<

schemaexport"

org.hibernate.tool.hbm2ddl.SchemaExportTask"

74<

schemaexportconfig="

quiet="

false"

text="

drop="

delimiter="

;

"

output="

schema-export.sql"

75<

76

77<

/project>

脚本很详细,看注释即可。

在使用xdoclet2hbm前,需要在pojo上设定javadoc注释,以告诉xdoclet如何进行解析。

one2one&

one2many的例子:

Child.java

1packagepo;

2

3/**

4*@hibernate.classtable="

child"

5*/

6@SuppressWarnings("

serial"

7publicclassChildimplementsjava.io.Serializable{

8

9//xdoclet注释有写在getter上与写在field上2种方法。

10//写在field上会自动生成access="

field"

,所以写在getter上更常用一些。

11

12privateStringid;

13privateStringname;

14privateFatherfather;

15

16/**

17*@hibernate.idgenerator-class="

uuid.hex"

column="

id"

length="

32"

18*/

19publicStringgetId(){

20returnthis.id;

21}

22

23publicvoidsetId(Stringid){

24this.id=id;

25}

26

27//基本支持所有的hibernate属性,所以想要啥设置就大胆的写吧

28/**

29*@hibernate.propertycolumn="

name"

not-null="

true"

type="

java.lang.String"

lazy="

30*/

31publicStringgetName(){

32returnthis.name;

33}

34

35publicvoidsetName(Stringname){

36this.name=name;

37}

38

39/**

40*@hibernate.many-to-onecolumn="

father_id"

41*/

42publicFathergetFather(){

43returnthis.father;

44}

45

46publicvoidsetFather(Fatherfather){

47this.father=father;

48}

49

50}

Father.java

3importjava.util.HashSet;

4importjava.util.Set;

5

6/**

7*@hibernate.classtable="

father"

8*/

9@SuppressWarnings("

10publicclassFatherimplementsjava.io.Serializable{

13

14privateStringname;

16privateIntegerage;

17

18privateSet<

Child>

children=newHashSet<

(0);

19

20/**

21*@hibernate.idgenerator-class="

22*/

23publicStringgetId(){

24returnthis.id;

27publicvoidsetId(Stringid){

28this.id=id;

29}

30

31/**

32*@hibernate.propertycolumn="

33*/

34publicStringgetName(){

35returnthis.name;

36}

37

38publicvoidsetName(Stringname){

39this.name=name;

40}

41

42/**

43*@hibernate.propertycolumn="

age"

java.lang.Integer"

44*/

45publicIntegergetAge(){

46returnage;

47}

48

49publicvoidsetAge(Integerage){

50this.age=age;

51}

52

53/**

54*@hibernate.settable="

55*@hibernate.keycolumn="

56*@hibernate.one-to-manyclass="

po.Child"

57*/

58publicSet<

getChildren(){

59returnchildren;

60}

61

62publicvoidsetChildren(Set<

children){

63this.children=children;

64}

65}

many2many的例子:

Student.java

student"

10publicclassStudentimplementsjava.io.Serializable{

14privateSet<

Teacher>

teachers=newHashSet<

27/**

28*@hibernate.propertycolumn="

29*/

30publicStringgetName(){

31returnthis.name;

32}

34publicvoidsetName(Stringname){

35this.name=name;

38/**

39*@hibernate.settable="

student_teacher_relation"

40*@hibernate.keycolumn="

student_id"

41*@hibernate.many-to-manyclass="

po.Teacher"

teacher_id"

42*/

43publicSet<

getTeachers(){

44returnteachers;

45}

46

47publicvoidsetTeachers(Set<

teachers){

48this.teachers=teachers;

49}

Teacher.java

teacher"

10publicclassTeacherimplementsjava.io.Serializable{

Student>

students=newHashSet<

po.Student"

getStudents(){

44returnstudents;

47publicvoidsetStudents(Set<

students){

48this.students=students;

50

51}

总结:

1.本文没有涉及hibernateannnotation模式,需要者请自行查阅相关资料。

2.XDoclet2没有XDoclet1代好找,推荐一个网址JarSearchEngine

3.本文未能涉及在开发中,程序运转时遇到DBschema结构变化而进行的动态自动转换技术。

如有高人知晓,请不吝赐教。

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 自然科学 > 物理

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2