jpa_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > jpa

jpa

 2014/11/25 22:07:29  haoningabc  程序员俱乐部  我要评论(0)
  • 摘要:可以使用jpa生成数据库表importjavax.persistence.EntityManagerFactory;importjavax.persistence.Persistence;publicclassTest{publicvoidcreateTable(){//可以验证生成表是否正确EntityManagerFactoryfactory=Persistence.createEntityManagerFactory("wechat");factory.close();
  • 标签:JPA
可以使用jpa生成数据库表
class="java" name="code">
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
public class Test {
	public void createTable() {
		// 可以验证生成表是否正确
		EntityManagerFactory factory = Persistence
				.createEntityManagerFactory("wechat");
		factory.close();
	}
	public static void main(String[] args) {
		Test t =new Test();
		t.createTable();

	}
}

persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" 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_2_0.xsd">
	<persistence-unit name="wechat" transaction-type="RESOURCE_LOCAL">
		<provider>org.hibernate.ejb.HibernatePersistence</provider>
		<class>com.wc.bean.OfUser</class>
		<class>com.wc.bean.WcUser</class>
		<class>com.wc.bean.WcLoginInfo</class>
		<class>com.wc.bean.WcMessages</class>
		<class>com.wc.bean.WcMusic</class>
		<class>com.wc.bean.WcFile</class>
		<properties>
			<property name="hibernate.connection.driver_class"
				value="com.mysql.jdbc.Driver" />
			<property name="hibernate.connection.url"
				value="jdbc:mysql://182.254.155.153:3306/hcapi?useUnicode=true&amp;characterEncoding=UTF-8" />
			<property name="hibernate.connection.username" value="root" />
			<property name="hibernate.connection.password"
				value="密码" />
			<property name="hibernate.hbm2ddl.auto" value="update" /> 
		</properties>
	</persistence-unit>
</persistence>

注意<property name="hibernate.hbm2ddl.auto" value="update" />
这个是自动生成表的
发表评论
用户名: 匿名