XDoclet with hibernate

xiaoxiao2021-03-06  27

Here will be used to generate related code for Hibernate (Customer.hbm.xml) to see XDoclets to provide work efficiency. One operating environment: 1, xdoclet2, ant3, hibernate needs JAR package has

XDoclet- / xxx / .jar xdoclet-hibernate-module- / xxx / .jar xdoclet-xjavadoc- / xxx / .jar xdoclet-xdoclet-module- / xxx / .jar log4j- / xxx / .jar Commons-Collections-2.0 .jar Commons-logging.jar The first four in front of the xdoclet (here "/ xxx /" means version number), the next few I think everyone is familiar, you can find it from many places. Two procedures look at the file structure. (Project Catalog) | -SRC (folder, named src.dir, storage source file) | -lib (folder, named lib.dir, store several JAR files mentioned above) | - *. jar | -bin (folder, name bin.dir) | -src (folder, stored generated * .java file, here will not be included) | -classes (folder, stored in * .class File) | -build.xml Look at the next source.

1, Customer.java / * * Created on 2004-12-20 * @Author roson * / package hibernate; import java.util.set; import java.util.collections; / ** * @Author roson * @since 1.0 * . @version 1.0 * @ hibernate.class tables = "customers" * / public class Customer {/ ** This customer's identifier field * / private long id; / ** This customer's name field * / private String name;. / ** . The customer's orders set * / private Set orders = Collections.EMPTY_SET;.. / ** The default construtor for Hibernate to instantiate with * / public Customer () {} / ** The getter method for this Customer's identifier * * @hibernate .id generator-class = "native" * / public long position () {return;} / ** the setter method for this customer's identifier. * / public void setId (long id) {this.id = ID;} / ** The getter method for this customer's name. * * @ Hibernate.property * / public string getname () {Return Name;} / ** the setter method for this customer's name. * / public void setname (string name) {this.name = name;} / ** the getter method for this customer's order. * * @ hibernate.set role = "Orders" * * @ hibernate.collection-key column = "customer_id" * @ hibernate.collection-one-to-man class = "order" * / public set getorders () {return odrs;} / ** the setter Method for this customer's orderrs. * / public void setORDERS (SET ORDERS) {this.orders = Orders;}} You can see a label than some comments in the source program.

XDoclets are identified through these tags that automatically generate XML files, in addition to Customer.java and ordinary javabean have no difference. Note: Here Customer.java is packaged as hibernate, if you want to change to change Build.xml.

2, build.xml < PATH ID = "lib.path"> 转载请注明原文地址:https://www.9cbs.com/read-76897.html


New Post(0)