<b>操作Ant和XDoclet自动产生映射文件例子</b>[Java编程]
本文“<b>操作Ant和XDoclet自动产生映射文件例子</b>[Java编程]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
//User.java
在企业中model类的属性大概有几百个并且还大概担当了很多属性,这样的model假如手写映射文件岂不是很大的工程!
这里介绍Ant+XDoclet配合来自动生成映射文件.
必备:Ant和XDocle的jar包.
操作很简单,自己写一个model类比方People.java,但是要自动生成映射文件这个类需求有注释,写一个build.xml文件,
下载Xdoclet,网址:http://xdoclet.sourceforge.net/
新建包com.test.model,存放实体类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 address) {
this.address = address;
}
}
以上是“<b>操作Ant和XDoclet自动产生映射文件例子</b>[Java编程]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
本文地址: | 与您的QQ/BBS好友分享! |