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;
}
}