Use Ant and Xdoclet to automatically generate a mapping file example

Source: Internet
Author: User
Tags set set

User.java

In the enterprise model class can have hundreds of properties and may also inherit a lot of attributes, such model if the handwriting mapping file is not a big project!

This article introduces Ant+xdoclet matching to automatically generate mapping files.

Prerequisites: Ant and Xdocle jar packages.

The operation is very simple, you write a model class such as People.java, but to automatically generate mapping files this class needs to have comments, write a build.xml file,

Download Xdoclet, URL: http://xdoclet.sourceforge.net/

New package Com.test.model, storing entity classes Group,user

package Dbdemo;


import java.util.Date;


import Java.util.Set;





/**





* @hibernate. Class table= "Users"


  *


* @author Ethan


  *


* Represents a User


  */


public class User {





private String UserID;





private String UserName;





private String password;





private String EmailAddress;





private Date Lastlogon;





private Set contacts;





private Set Books;





private address address;





     /**


* @hibernate. Property column= "EmailAddress" type= "string"


* @return String


      */





public String getemailaddress () {


return emailaddress;


     }





     /**


* @hibernate. Property column= "Lastlogon" type= "date"


* @return Date


      */





public Date Getlastlogon () {


return lastlogon;


     }





     /**


* @hibernate. Property column= "Password" type= "string"


* @return String


      */





public String GetPassword () {


return password;


     }





     /**


* @hibernate. ID generator-class= "Assigned" type= "string"


* column= "LogonId"


* @return String


      */





public String GetUserID () {


return UserID;


     }





     /**


* @hibernate. Property column= "Name" type= "string"


* @return String


      */





public String GetUserName () {


return userName;


     }





     /**


* @param string


      */





public void Setemailaddress (string string) {


EmailAddress = string;


     }





     /**


* @param string


      */





public void Setlastlogon (date date) {


Lastlogon = date;


     }





     /**


* @param string


      */





public void SetPassword (string string) {


Password = string;


     }





     /**


* @param string


      */





public void Setuserid (string string) {


UserID = string;


     }





     /**


* @param string


      */





public void Setusername (string string) {


userName = string;


     }





     /**


* @hibernate. Set role= "Contacts" table= "Contacts"


* cascade= "All" readonly= "true"


* @hibernate. Collection-key column= "user_id"


* @hibernate. Collection-one-to-many class= "Dbdemo. Contact "


* @return Java.util.Set


      */





public Set getcontacts () {


return contacts;


     }





     /**


* @param set


      */





public void Setcontacts (set set) {


contacts = set;


     }





     /**


* @hibernate. Set role= "Books" table= "Book_user_link"


* cascade= "All" eadonly= "true"


* @hibernate. Collection-key column= "UserID"


* @hibernate. Collection-many-to-many


* class= "Dbdemo. Book "column=" BookID "


* @return Java.util.Set


      */


public Set getbooks () {


return books;


     }





     /**


* @param set


      */





public void Setbooks (set set) {


books = set;


     }





     /**


* @hibernate. One-to-one class= "Dbdemo. Address "


* @return Dbdemo. Address


      */





public Address getaddress () {


return address;


     }





     /**


* @param address


      */





public void setaddress (address) {


this.address = address;


}





}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.