真的是没办法了!jpa大神请进
弄了一晚上,就是无法自动创建表,单元测试通过了,没报错,就是不能创建表,用的是sqlServer2008,数据库连接是没问题的,在线等大神
code如下:
persistence.xml
<?xml version="1.0"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" 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_1_0.xsd" version="1.0">
<!-- file:///D:\hibernate\hibernate-entitymanager-3.3.2.CR1\resources\org\hibernate\ejb\persistence_1_0.xsd -->
<persistence-unit name="demo" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>
<property name="hibernate.connection.driver_class" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
<property name="hibernate.connection.username" value="sa"/>
<property name="hibernate.connection.password" value="123"/>
<property name="hibernate.connection.url" value="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=demo"/>
<property name="hibernate.max_fetch_depth" value="3"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.jdbc.fetch_size" value="18"/>
<property name="hibernate.jdbc.batch_size" value="10"/>
<property name="hibernate.show_sql" value="false"/>
<property name="hibernate.format_sql" value="false"/>
</properties>
java代码
package com.hongle.bean.product;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
public class ProductType {
private int typeId;
@Id @GeneratedValue(strategy=GenerationType.AUTO)
public int getTypeId() {
return typeId;
}
public void setTypeId(int typeId) {
this.typeId = typeId;
}
}
java代码
package junit.test;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.junit.BeforeClass;
import org.junit.Test;
import junit.framework.TestCase;
public class ProductTest{
@BeforeClass
public static void setUpBeforeClass() throws Exception {
}
@Test
public void testRun(){
Persistence.createEntityManagerFactory("demo");
}
}
可恨的是没有报错,改都不知道怎么改