hibernate.hbm2ddl.auto 问题小记

总是在一些小问题上跌倒。
最近做单DAO服务类,在测试的时候,为了简单,采用hibernate.hbm2ddl.auto自动生成表,但我发现不管是update还是create都没有在数据库中建立表,这太不应该了,经过几番周折,发现问题所在:
这是建立order表不成功的POJO:
@Entity
public class Order {
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private int id;
	
	private Date createDate;
	
	@OneToMany(targetEntity=Item.class, mappedBy="order", cascade=CascadeType.ALL)
	private Set<Item> items;

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public Date getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	public Set<Item> getItems() {
		return items;
	}

	public void setItems(Set<Item> items) {
		this.items = items;
	}
	
}

改过后建立order表成功的POJO:
@Entity
[b]@Table(name="ORDER", schema="hibernate")[/b]
public class Order {
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	[b]@Column(nullable=false, unique=true)[/b]	
         private int id;
	
	private Date createDate;
	
	@OneToMany(targetEntity=Item.class, mappedBy="order", cascade=CascadeType.ALL)
	private Set<Item> items;

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public Date getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	public Set<Item> getItems() {
		return items;
	}

	public void setItems(Set<Item> items) {
		this.items = items;
	}
	
}

希望能给遇到同样问题的朋友提个醒

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