hibernate3.2的annotations的使用

package com.domain;

import java.io.Serializable;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;

@Entity
@Table(name = "user")
public class User implements Serializable {
	private static final long serialVersionUID = -5370796872638524212L;

	private int userID;
	private String userName;
	private String userPwd;
	private List<Artle> artles;

	@Id
	@GeneratedValue
	@Column(name = "userID", unique = true, nullable = false)
	public int getUserID() {
		return userID;
	}

	public void setUserID(int userID) {
		this.userID = userID;
	}

	@Column(name = "userName", nullable = false, length = 20)
	@NotNull
	@Length(max = 20)
	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	@Column(name = "userPwd", nullable = false, length = 20)
	@NotNull
	@Length(max = 20)
	public String getUserPwd() {
		return userPwd;
	}

	public void setUserPwd(String userPwd) {
		this.userPwd = userPwd;
	}

	@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, fetch = FetchType.EAGER, targetEntity = Artle.class)
	public List<Artle> getArtles() {
		return artles;
	}

	public void setArtles(List<Artle> artles) {
		this.artles = artles;
	}

}

 

package com.domain;

import java.io.Serializable;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name = "artle")
public class Artle implements Serializable {

	private static final long serialVersionUID = -6278884950005243251L;

	private int artleID;
	private String artleContent;
	private User user;

	@Id
	@GeneratedValue
	@Column(name = "artleID", unique = true, nullable = false)
	public int getArtleID() {
		return artleID;
	}

	public void setArtleID(int artleID) {
		this.artleID = artleID;
	}

	@Column(name = "artleContent", nullable = false)
	public String getArtleContent() {
		return artleContent;
	}

	public void setArtleContent(String artleContent) {
		this.artleContent = artleContent;
	}

	@ManyToOne(cascade={CascadeType.MERGE})
	@JoinColumn(name="userID")
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	

}

 

你可能感兴趣的:(Hibernate,xml)