Other technology and hibernate-xdoclet
Using Hibernate, the entity class, you need a map file, XDoclet is added to the @ hibernate.xxx indication similar to Javadoc while writing, and then automatically generates the MAP file with xdoclets to make the write program more convenient.
Using XDoclet usually uses Ant, and adds the XDoclet part in building.xml. XDoclets need to have the corresponding JAR file support, but because xdoclets are used when Ant is running, the XDoclet's JAR may not be placed under WebApps /../WEB-INF / LIB, but also put a directory (sometimes xdoclet) JAR will conflict with other JAR conflicts)
From xdoclet.zip or tar.gz, you can put it under a separate directory, such as lib-xdoc, generally: (take 1.2 version)
XDoclet-1.2.jar xdoclet-xdoclet-module-1.2.jar xdoclet-hibernate-module-1.2.jar xjavadoc-1.0.2.jar
Other common JAR, Hibernate, etc. also used, such as commons-logging-x.x.x.jar, Xerces-X.x.x.jar, can be placed in the lib directory.
Directory Structure Web-INF
LIB lib-xdoc src class build.xml web.xml
In this way, JARs under the Ant's build.xml is simultaneously joined, using XDoclets when compiling, and do not use xdoclet when running.
Build.xml:
XML Version = "1.0" encoding = "UTF-8"?>
fileset>
fileset>
path>
target>
target>
ClassName = "xdoclet.modules.hibLETSK"> taskdef> destdir = "$ {classs}" ExcludedTags = "@ version, @ Author, @ TODO" Force = "True" Verbose = "True"> fileset> hibernatedoclet> target> provject> Examples of using xdoclets: Example 1.org.java represents all organizations of a company, form a tree structure, is an org may have a father's org With MANY-TO-One / One-To-Many, use the same column (parent) to itself (bean.org), there is an inverse Package bean; import java.util. *; / ** * @ hibernate.class table = "test_org" * / public class org extends persistent { // Note: ID in persistent, private string name; private org parent; private set children = new treset (); / ** * @ hibernate.property length = "60" * / public string getname () {return name;} Public void setname (string value) {name = value;} / ** * @ hibernate.many-to-one class = "bean.org" column = "parent" * / public org getparent () {return parent;} PUBLIC Void setParent (org value) {parent = value;} / ** * @ hibernate.set inverse = "true" lazy = "true" cascade = "all" * @ hibernate.collection-key column = "parent" * @Hibernate .COLLECTION-One-to-Many Class = "bean.org" * / public set getchildren () {Return Children (} public void setchildren (set value) {children = value;}}} Persistent.java Package bean; Import net.sf.hibLeTable; Import net.sf.hibailure; / ** * @ hibernate.class table = "test_persistent" * / Public class persistent implements validatable { Protected Int ID; / ** * @ hibernate.id generator-class = "increment" type = "int" Unsaved-value = "null" * / Public int getId () { Return ID; } Public void setid (int id) { THIS.ID = ID; } Public void validate () THROWS VALIDATIONFAILURE {} } Automatically generated MAP files are as follows: Org.hbm.xml xml version = "1.0"?> The table is the same (Test_user_position), in the position, "Inverse", to achieve bidirectional association (Bidirectional Association) Users.java: Package bean; import java.util. *; / ** * @ hibernate.class table = "test_user" * / public class user extends persistent { // ... private set positions = new treset (); / ** * @ hibernate.set table = "test_user_position" lazy = "true" * @ hibernate.collection-key column = "user_id" * @Hibernate .COLLECTION-MANY-TO-MANY CLASS = "bean.position" column = "position_id" * / public set getPositions () {Return Positions;}}} = value;}}}}} Position.java Package bean; import java.util. *; / ** * @ hibernate.class table = "test_position" * / public class position extends persistent {// ... private set users = new treset (); / * * * @ hibernate.set inverse = "true" lazy = "true" table = "test_user_position" * @ hibernate.collection-key column = "position_id" * @ hibernate.collection-man-to-many class = "bean.user "column =" user_id "* / public set getusers () {return user {user = value;}}}}}} summary: With xDoclets, it is convenient to generate Hibernate's MAP files to speed up development. Note: The corresponding column should be correct when using two-way association (Bidirectional Association), otherwise xDoclet does not report error, but the generated database table is incorrect. reference: Hibernate master: www.hibernate.org Hibernate xdoclet: http://www.chinaunix.net/jh/26/92019.html XDoclet master: http://xdoclet.sourceforge.net/