JPA 无法自动建表
本帖最后由 zhanglt 于 2011-06-03 17:03:50 编辑
最近在学JPA,遇到一个问题,发现代码无法自动建表。代码如下:
package com.babasport.bean.product;
import javax.persistence.Entity;
import javax.persistence.GenerationType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@Entity
public class ProductType {
private Integer typeid;
@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
public Integer getTypeid() {
return typeid;
}
public void setTypeid(Integer typeid) {
this.typeid = typeid;
}
}
package junit.test;
import javax.persistence.Persistence;
import javax.persistence.*;
import com.babasport.bean.product.*;
import org.junit.BeforeClass;
import org.junit.Test;
public class Product {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
}
@Test
public void runTest(){
Persistence.createEntityManagerFactory("babasport");
}
}
配置文件如下:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
org.hibernate.ejb.HibernatePersistence