在IntelliJ Idea中集成 Hibernate Xdoclet 开发
在hibernate开发中,我们经常使用Xdoclet标签,这样一来可以省去配置的功夫,二来看起来更容易理解,如果在IDE工具中集成了Xdoclet的提示则大大提高xdoclet标签的使用正确性和开发效率。
在ItelliJ Idea 6中集成Hibernate Xdoclet,步骤如下:
1.下载hibernate.xml文件到 %IDEA_HOME%/config/templates下,一般在C:/Documents and Settings/hunterk/.IntelliJIdea60/config/templates
下载hibernate.xml
<? xml version="1.0" encoding="UTF-8" ?>
< templateSet group ="hibernate" >
< template name ="hib.array" value ="@hibernate.array table="$table$" *
cascade="$cascade$" "
description ="Defines an array" toReformat ="true" toShortenFQNames ="true" >
< variable name ="table" expression ="""" defaultValue ="""" alwaysStopAt ="true" />
< variable name ="cascade" expression ="""" defaultValue =""update"" alwaysStopAt ="true" />
< context >
< option name ="JAVA_CODE" value ="false" />
< option name ="JAVA_COMMENT" value ="true" />
< option name ="JAVA_STRING" value ="false" />
< option name ="XML" value ="false" />
< option name ="HTML" value ="false" />
< option name ="JSP" value ="false" />
< option name ="COMPLETION" value ="false" />
< option name ="OTHER" value ="false" />
</ context >
</ template >
< template name ="hib.bag" value ="@hibernate.bag
inverse="$readonly$" * table="$table$" *
lazy="$lazy$" * cascade="$cascade$" "
description ="Defines a bag" toReformat ="true"
toShortenFQNames ="true" >
< variable name ="readonly" expression =""""
defaultValue =""false"" alwaysStopAt ="true" />
< variable name ="table" expression =""""
defaultValue ="""" alwaysStopAt ="true" />
< variable name ="lazy" expression =""""
defaultValue =""false"" alwaysStopAt ="true" />
< variable name ="cascade" expression =""""
defaultValue =""update"" alwaysStopAt ="true" />
< context >
< option name ="JAVA_CODE" value ="false" />
< option name ="JAVA_COMMENT" value ="true" />
< option name ="JAVA_STRING" value ="false" />
< option name ="XML" value ="false" />
< option name ="HTML" value ="false" />
< option name ="JSP" value ="false" />
< option name ="COMPLETION" value ="false" />
< option name ="OTHER" value ="false" />
</ context >
</ template >
< template name ="hib.class" value ="@hibernate.class
table="$table$" * mutable="$mutable$" *
proxy="$proxy$"" description ="Used to generate decriptor file for
Hibernate" toReformat ="true" toShortenFQNames ="true" >
< variable name ="table" expression ="decapitalize(className())"
defaultValue ="" alwaysStopAt ="true" />
< variable name ="mutable" expression =""""
defaultValue =""read-write"" alwaysStopAt ="true" />
< variable name ="proxy" expression ="qualifiedClassName()"
defaultValue ="" alwaysStopAt ="true" />
< context >
< option name ="JAVA_CODE" value ="false" />
< option name ="JAVA_COMMENT" value ="true" />
< option name ="JAVA_STRING" value ="false" />
< option name ="XML" value ="false" />
< option name ="HTML" value ="false" />
< option name ="JSP" value ="false" />
< option name ="COMPLETION" value ="false" />
< option name ="OTHER" value ="false" />
</ context >
</ template >
< template name ="hib.colele" value ="@hibernate.collection-element
column="$column$"" description ="Declares a collection element"
toReformat ="true" toShortenFQNames ="true" >
< variable name ="column" expression =""""
defaultValue ="" alwaysStopAt ="true" />
< context >
< option name ="JAVA_CODE" value ="false" />
< option name ="JAVA_COMMENT" value ="true" />
< option name ="JAVA_STRING" value ="false" />
< option name ="XML" value ="false" />
< option name ="HTML" value ="false" />
< option name ="JSP" value ="false" />
< option name ="COMPLETION" value ="false" />
< option name ="OTHER" value ="false" />
</ context >
</ template >
< template name ="hib.colidx" value ="@hibernate.collection-index
column="$column$"" description ="Declares a collection index"
toReformat ="true" toShortenFQNames ="true" >
< variable name ="column" expression =""""
defaultValue ="" alwaysStopAt ="true" />
< context >
< option name ="JAVA_CODE" value ="false" />
< option name ="JAVA_COMMENT" value ="true" />
< option name ="JAVA_STRING" value ="false" />
< option name ="XML" value ="false" />
< option name ="HTML" value ="false" />
< option name ="JSP" value ="false" />
< option name ="COMPLETION" value ="false" />
< option name ="OTHER" value ="false" />
</ context >
</ template >
< template name ="hib.colkey" value ="@hibernate.collection-key
column="$column$" *
generator-class="$generatorclass$"" description ="Declares a collection
key" toReformat ="true" toShortenFQNames ="true" >
< variable name ="column" expression =""""
defaultValue ="" alwaysStopAt ="true" />
< variable name ="generatorclass" expression =""""
defaultValue ="" alwaysStopAt ="true" />
< context >
< option name ="JAVA_CODE" value ="false" />
< option name ="JAVA_COMMENT" value ="true" />
< option name ="JAVA_STRING" value ="false" />
< option name ="XML" value ="false" />
< option name ="HTML" value ="false" />
< option name ="JSP" value ="false" />
< option name ="COMPLETION" value ="false" />
< option name ="OTHER" value ="false" />
</ context >
</ template >
< template name ="hib.colmtm" value ="@hibernate.collection-many-to-many
column="$column$" * class="$class$""
description ="Declares a many-to-many relationship" toReformat ="true"
toShortenFQNames ="true" >
< variable name ="column" expression =""""
defaultValue ="" alwaysStopAt ="true" />
< variable name ="class" expression =""""
defaultValue ="""" alwaysStopAt ="true" />
< context >
< option name ="JAVA_CODE" value ="false" />
< option name ="JAVA_COMMENT" value ="true" />
< option name ="JAVA_STRING" value ="false" />
< option name ="XML" value ="false" />
< option name ="HTML" value ="false" />
< option name ="JSP" value ="false" />
< option name ="COMPLETION" value ="false" />
< option name ="OTHER" value ="false" />
</ context >
</ template >
< template name ="hib.colotm" value ="@hibernate.collection-one-to-many
class="$class$"" description ="Declares a one-to-many relationship"
toReformat ="true" toShortenFQNames ="true" >
< variable name ="class" expression =""""
defaultValue ="""" alwaysStopAt ="true" />
< context >
< option name ="JAVA_CODE" value ="false" />
< option name ="JAVA_COMMENT" value ="true" />
< option name ="JAVA_STRING" value ="false" />
< option name ="XML" value ="false" />
< option name ="HTML" value ="false" />
< option name ="JSP" value ="false" />
< option name ="COMPLETION" value ="false" />
< option name ="OTHER" value ="false" />
</ context >
</ template >
< template name ="hib.comele" value ="@hibernate.composite-element
class="$class$"" description ="Declares a composite collection
element" toReformat ="true" toShortenFQNames ="true" >
< variable name ="class" expression =""""
defaultValue ="""" alwaysStopAt ="true" />
< context >
< option name ="JAVA_CODE" value ="false" />
< option name ="JAVA_COMMENT" value ="true" />
< option name ="JAVA_STRING" value ="false" />
< option name ="XML" value ="false" />
< option name ="HTML" value ="false" />
< option name ="JSP" value ="false" />
< option name ="COMPLETION" value ="false" />
< option name ="OTHER" value ="false" />
</ context >
</ template >
< template name ="hib.comp" value ="@hibernate.component
class="$class$"" description ="Declare a component"
toReformat ="true" toShortenFQNames ="true" >
< variable name ="class" expression =""""
defaultValue ="" alwaysStopAt ="true" />
< context >
< option name ="JAVA_CODE" value ="false" />
< option name ="JAVA_COMMENT" value ="true" />
< option name ="JAVA_STRING" value ="false" />
< option name ="XML" value ="false" />
< option name ="HTML" value ="false" />
< option name ="JSP" value ="false" />
< option name ="COMPLETION" value ="false" />
< option name ="OTHER" value ="false" />
</ context >
</ template >
< template name ="hib.disc" value ="@hibernate.discriminator
column="$column$"" description ="Defines a discriminator"
toReformat ="true" toShortenFQNames ="true" >
< variable name ="column" expression =""""
defaultValue ="" alwaysStopAt ="true" />
< context >
< option name ="JAVA_CODE" value ="false" />
< option name ="JAVA_COMMENT" value ="true" />
< option name ="JAVA_STRING" value ="false" />
< option name ="XML" value ="false" />
< option name ="HTML" value ="false" />
< option name ="JSP" value ="false" />
< option name ="COMPLETION" value ="false" />
< option name ="OTHER" value ="false" />
</ context >
</ template >
< template name ="hib.id" value ="@hibernate.id
column="$column$" *
unsaved-value="$unsavedvalue$" *
generator-class="$generatorclass$" " description ="Declares an
identifier property" toReformat ="true" toShortenFQNames ="true" >
< variable name ="column" expression =""""
defaultValue ="" alwaysStopAt ="true" />
< variable name ="unsavedvalue" expression =""""
defaultValue =""null"" alwaysStopAt ="true" />
< variable name ="generatorclass" expression =""""
defaultValue =""native"" alwaysStopAt ="true" />
< context >
< option name ="JAVA_CODE" value ="false" />
< option name ="JAVA_COMMENT" value ="true" />
< option name ="JAVA_STRING" value ="false" />
< option name ="XML" value ="false" />
< option name ="HTML" value ="false" />
< option name ="JSP" value ="false" />
< option name ="COMPLETION" value ="false" />
< option name ="OTHER" value ="false" />
</ context >
</ template >
< template name ="hib.list" value ="@hibernate.list
table="$table$" * lazy="$lazy$" *
cascade="$cascade$" " description ="Defines a list"
toReformat ="true" toShortenFQNames ="true" >
< variable name ="table" expression =""""
defaultValue ="""" alwaysStopAt ="true" />
< variable name ="lazy" expression =""""
defaultValue =""false"" alwaysStopAt ="true" />
< variable name ="cascade" expression =""""
defaultValue =""update"" alwaysStopAt ="true" />
< context >
< option name ="JAVA_CODE" value ="false" />
< option name ="JAVA_COMMENT" value ="true" />
< option name ="JAVA_STRING" value ="false" />
< option name ="XML" value ="false" />
< option name ="HTML" value ="false" />
< option name ="JSP" value ="false" />
< option name ="COMPLETION" value ="false" />
< option name ="OTHER" value ="false" />
</ context >
</ template >
< template name ="hib.map" value ="@hibernate.map
table="$table$" * lazy="$lazy$" *
cascade="$cascade$" " description ="Defines a map"
toReformat ="true" toShortenFQNames ="true" >
< variable name ="table" expression =""""
defaultValue ="""" alwaysStopAt ="true" />
< variable name ="lazy" expression =""""
defaultValue =""false"" alwaysStopAt ="true" />
< variable name ="cascade" expression =""""
defaultValue =""update"" alwaysStopAt ="true" />
< context >
< option name ="JAVA_CODE" value ="false" />
< option name ="JAVA_COMMENT" value ="true" />
< option name ="JAVA_STRING" value ="false" />
< option name ="XML" value ="false" />
< option name ="HTML" value ="false" />
< option name ="JSP" value ="false" />
< option name ="COMPLETION" value ="false" />
< option name ="OTHER" value ="false" />
</ context >
</ template >
< template name ="hib.mto" value ="@hibernate.many-to-one
column="$column$" * cascade="$cascade$" *
class="$class$" * outer-join="$outerjoin$" *
unique="$unique$" " description ="Declares a many-to-one
association" toReformat ="true" toShortenFQNames ="true" >
< variable name ="column" expression =""""
defaultValue ="" alwaysStopAt ="true" />
< variable name ="cascade" expression =""""
defaultValue =""update"" alwaysStopAt ="true" />
< variable name ="class" expression =""""
defaultValue ="" alwaysStopAt ="true" />
< variable name ="outerjoin" expression =""""
defaultValue =""auto"" alwaysStopAt ="true" />
< variable name ="unique" expression =""""
defaultValue =""false"" alwaysStopAt ="true" />
< context >
< option name ="JAVA_CODE" value ="false" />
< option name ="JAVA_COMMENT" value ="true" />
< option name ="JAVA_STRING" value ="false" />
< option name ="XML" value ="false" />
< option name ="HTML" value ="false" />
< option name ="JSP" value ="false" />
< option name ="COMPLETION" value ="false" />
< option name ="OTHER" value ="false" />
</ context >
</ template >
< template name ="hib.oto" value ="@hibernate.one-to-one
cascade="$cascade$" * class="$class$" *
outer-join="$outerjoin$" " description ="Declares a one-to-one
association" toReformat ="true" toShortenFQNames ="true" >
< variable name ="cascade" expression =""""
defaultValue =""update"" alwaysStopAt ="true" />
< variable name ="class" expression =""""
defaultValue ="" alwaysStopAt ="true" />
< variable name ="outerjoin" expression =""""
defaultValue =""auto"" alwaysStopAt ="true" />
< context >
< option name ="JAVA_CODE" value ="false" />
< option name ="JAVA_COMMENT" value ="true" />
< option name ="JAVA_STRING" value ="false" />
< option name ="XML" value ="false" />
< option name ="HTML" value ="false" />
< option name ="JSP" value ="false" />
< option name ="COMPLETION" value ="false" />
< option name ="OTHER" value ="false" />
</ context >
</ template >
< template name ="hib.parray" value ="@hibernate.primitive-array
table="$table$" * cascade="$cascade$" "
description ="Defines a primitive array" toReformat ="true"
toShortenFQNames ="true" >
< variable name ="table" expression =""""
defaultValue ="""" alwaysStopAt ="true" />
< variable name ="cascade" expression =""""
defaultValue =""update"" alwaysStopAt ="true" />
< context >
< option name ="JAVA_CODE" value ="false" />
< option name ="JAVA_COMMENT" value ="true" />
< option name ="JAVA_STRING" value ="false" />
< option name ="XML" value ="false" />
< option name ="HTML" value ="false" />
< option name ="JSP" value ="false" />
< option name ="COMPLETION" value ="false" />
< option name ="OTHER" value ="false" />
</ context >
</ template >
< template name ="hib.prop" value ="@hibernate.property
column="$column$" * not-null="$notnull$" *
unique="$unique$" " description ="Defines a property"
toReformat ="true" toShortenFQNames ="true" >
< variable name ="column" expression =""""
defaultValue ="" alwaysStopAt ="true" />
< variable name ="notnull" expression =""""
defaultValue =""false"" alwaysStopAt ="true" />
< variable name ="unique" expression =""""
defaultValue =""false"" alwaysStopAt ="true" />
< context >
< option name ="JAVA_CODE" value ="false" />
< option name ="JAVA_COMMENT" value ="true" />
< option name ="JAVA_STRING" value ="false" />
< option name ="XML" value ="false" />
< option name ="HTML" value ="false" />
< option name ="JSP" value ="false" />
< option name ="COMPLETION" value ="false" />
< option name ="OTHER" value ="false" />
</ context >
</ template >
< template name ="hib.query" value ="@hibernate.query
name="$name$" * query="$query$""
description ="Declares a named query for class" toReformat ="true"
toShortenFQNames ="true" >
< variable name ="name" expression =""""
defaultValue ="""" alwaysStopAt ="true" />
< variable name ="query" expression =""""
defaultValue ="""" alwaysStopAt ="true" />
< context >
< option name ="JAVA_CODE" value ="false" />
< option name ="JAVA_COMMENT" value ="true" />
< option name ="JAVA_STRING" value ="false" />
< option name ="XML" value ="false" />
< option name ="HTML" value ="false" />
< option name ="JSP" value ="false" />
< option name ="COMPLETION" value ="false" />
< option name ="OTHER" value ="false" />
</ context >
</ template >
< template name ="hib.set" value ="@hibernate.set
inverse="$readonly$" * table="$table$" *
lazy="$lazy$" * cascade="$cascade$" "
description ="Defines a set" toReformat ="true"
toShortenFQNames ="true" >
< variable name ="readonly" expression =""""
defaultValue =""false"" alwaysStopAt ="true" />
< variable name ="table" expression =""""
defaultValue ="""" alwaysStopAt ="true" />
< variable name ="lazy" expression =""""
defaultValue =""false"" alwaysStopAt ="true" />
< variable name ="cascade" expression =""""
defaultValue =""update"" alwaysStopAt ="true" />
< context >
< option name ="JAVA_CODE" value ="false" />
< option name ="JAVA_COMMENT" value ="true" />
< option name ="JAVA_STRING" value ="false" />
< option name ="XML" value ="false" />
< option name ="HTML" value ="false" />
< option name ="JSP" value ="false" />
< option name ="COMPLETION" value ="false" />
< option name ="OTHER" value ="false" />
</ context >
</ template >
< template name ="hib.subclass" value ="@hibernate.subclass
discriminator-value="$expr$"" description ="Declare the current class as
subclass" toReformat ="true" toShortenFQNames ="true" >
< variable name ="expr" expression =""""
defaultValue ="" alwaysStopAt ="true" />
< context >
< option name ="JAVA_CODE" value ="false" />
< option name ="JAVA_COMMENT" value ="true" />
< option name ="JAVA_STRING" value ="false" />
< option name ="XML" value ="false" />
< option name ="HTML" value ="false" />
< option name ="JSP" value ="false" />
< option name ="COMPLETION" value ="false" />
< option name ="OTHER" value ="false" />
</ context >
</ template >
< template name ="hib.ts" value ="@hibernate.timestamp
column="$column$"" description ="Declares a timestamp property"
toReformat ="true" toShortenFQNames ="true" >
< variable name ="column" expression =""""
defaultValue ="" alwaysStopAt ="true" />
< context >
< option name ="JAVA_CODE" value ="false" />
< option name ="JAVA_COMMENT" value ="true" />
< option name ="JAVA_STRING" value ="false" />
< option name ="XML" value ="false" />
< option name ="HTML" value ="false" />
< option name ="JSP" value ="false" />
< option name ="COMPLETION" value ="false" />
< option name ="OTHER" value ="false" />
</ context >
</ template >
< template name ="hib.ver" value ="@hibernate.version
column="$column$"" description ="Declares a version property"
toReformat ="true" toShortenFQNames ="true" >
< variable name ="column" expression =""""
defaultValue ="" alwaysStopAt ="true" />
< variable name ="type" expression =""""
defaultValue ="" alwaysStopAt ="true" />
< variable name ="unsavedvalue" expression =""""
defaultValue =""null"" alwaysStopAt ="true" />
< variable name ="generatorclass" expression =""""
defaultValue =""native"" alwaysStopAt ="true" />
< context >
< option name ="JAVA_CODE" value ="false" />
< option name ="JAVA_COMMENT" value ="true" />
< option name ="JAVA_STRING" value ="false" />
< option name ="XML" value ="false" />
< option name ="HTML" value ="false" />
< option name ="JSP" value ="false" />
< option name ="COMPLETION" value ="false" />
< option name ="OTHER" value ="false" />
</ context >
</ template >
</ templateSet >
2.重启Idea
3.在Idea的File->Setting->Errors->IDE Profiles->Default->Inspections->General->Declaration has javadoc problems->Additional JavaDoc Tags的对话框添加以下内容:
hibernate.class
,
hibernate.discriminator
,
hibernate.subclass
,
hibernate.query
,
hibernate.property
,
hibernate.component
,
hibernate.id
,
hibernate.version
,,
hibernate.timestamp
,
hibernate.many-to-one
,
hibernate.one-to-one
,
hibernate.set
,
hibernate.bag
,
hibernate.list
,
hibernate.map
,
hibernate.array
,
hibernate.primitive-array
,
hibernate.collection-key
,
hibernate.collection-index
,
hibernate.collection-element
,
hibernate.composite-element
,
hibernate.collection-many-to-many
,
hibernate.collection-one-to-many
如图:
4.使用在编写代码时按Ctrl+Space (如果你的这个热键给输入法占了,设置别的热键吧!)
5.附件:Hibernate的Xdoclet Live Templates
hib.array
/**
* @hibernate.array table = " $table "
* cascade = " $cascade "
**/
where $table defaults to "" , and $cascade defaults to " update "
hib.bag
/**
* @hibernate.bag inverse = " $inverse "
* table = " $table "
* lazy = " $lazy "
* cascade = " $cascade "
**/
where $inverse defaults to " false " , $table defaults to "" , $lazy defaults to " false " , and $cascade defaults to " update "
hib.class
/**
* @hibernate.class table = " $table "
* mutable = " $mutable "
* proxy = " $proxy "
**/
where $table defaults to decapitalize(className()) , $mutable defaults to " true " , and $proxy defaults to qualifiedClassName()
hib.colele
/**
* @hibernate.collection-element column = " $column "
**/
where $column defaults to ""
hib.colidx
/**
* @hibernate.collection-index column = " $column "
**/
where $column defaults to ""
hib.colkey
/**
* @hibernate.collection-key column = " $column "
* generator-class = " $generatorclass "
**/
where $column defaults to "" , and $generatorclass defaults to ""
hib.colmtm
/**
* @hibernate.collection-many-to-many column = " $column "
* class = " $class "
**/
where $column defaults to "" , and $class defaults to ""
hib.colotm
/**
* @hibernate.collection-one-to-many class = " $class "
**/
where $class defaults to ""
hib.comele
/**
* @hibernate.composite-element class = " $class "
**/
where $class defaults to ""
hib.comp
/**
* @hibernate.component class = " $class "
**/
where $class defaults to ""
hib.disc
/**
* @hibernate.discriminator column = " $column "
**/
where $column defaults to ""
hib.id
/**
* @hibernate.id column = " $column "
* unsaved-value = " $unsavedvalue "
* generator-class = " $generatorclass "
**/
where $column defaults to "" , $unsavedvalue defaults to " null " , and $generatorclass defaults to " native "
hib.list
/**
* @hibernate.list table = " $table "
* lazy = " $lazy "
* cascade = " $cascade "
**/
where $table defaults to "" , $lazy defaults to " false " , and $cascade defaults to " update "
hib.map
/**
* @hibernate.map table = " $table "
* lazy = " $lazy "
* cascade = " $cascade "
**/
where $table defaults to "" , $lazy defaults to " false " , and $cascade defaults to " update "
hib.mto
/**
* @hibernate.many-to-one column = " $column "
* cascade = " $cascade "
* class = " $class "
* outer-join = " $outerjoin "
* unique = " $unique "
**/
where $column defaults to "" , $cascade defaults to " update " , $class defaults to "" , $outerjoin defaults to " auto " , and $unique defaults to " false "
hib.oto
/**
* hibernate.one-to-one cascade = " $cascade "
* class = " $class "
* outer-join = " $outerjoin "
**/
where $cascade defaults to " update " , $class defaults to "" , and $outerjoin defaults to " auto "
hib.parray4
/**
* @hibernate.primitive-array table = " $table "
* cascade = " $cascade "
**/
where $table defaults to "" , and $cascade defaults to " update "
hib.prop
/**
* hibernate.property column = " $column "
* not-null = " $notnull "
* unique = " $unique "
**/
where $column defaults to "" , $notnull defaults to " false " , and $unique defaults to " false "
hib.query
/**
*@hibernate.query name = " $name "
* query = " $query "
**/
where $name defaults to "" , and $query defaults to ""
hib.set
/**
* @hibernate.set inverse = " $inverse "
* table = " $table "
* lazy = " $lazy "
* cascade = " $cascade "
**/
where $inverse defaults to " false " , $table defaults to "" , $lazy defaults to " false " , and $cascade defaults to " update "
hib.subclass
/**
* @hibernate.subclass discriminator-value = " $discriminatorvalue "
**/
where $discriminatorvalue defaults to ""
hib.ts
/**
* @hibernate.timestamp column = " $column "
**/
where $column defaults to ""
hib.ver
/**
* @hibernate.version column = " $column "
**/
where $column defaults to ""