最近去了一家公司面试,一切都还顺利,在最后的时候,项目经理问我会不会用JPA,我晕~!以前只是听说过,知道是java持久化api,但是里面的细节就不知道了,于是开始学习JPA,丰富一下自己的知识,哈哈,查漏补缺吧。
在网上找到了一个jpa与Hibernate集成的配置文件persistence.xml,如下
<?xml version="1.0" encoding="UTF-8"?> <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"> <persistence-unit name="jpa1" transaction-type="RESOURCE_LOCAL"> <class>org.hibernate.ejb.HibernatePersistence</class> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/> <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/> <property name="hibernate.connection.username" value="root"/> <property name="hibernate.connection.password" value="xxx"/> <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/jpademo"/> <property name="hibernate.hbm2ddl.auto" value="update"/> <property name="hibernate.show_sql" value="true"/> </properties> </persistence-unit> </persistence>