Could not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceE

Could not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: Cannot open connection

檢查一下 數據源 配置, 看你的異常應該是 使用 JTA 事物 ,容器沒有實例化 EntityManager java

 1 <?xml version="1.0"?>
 2 <persistence xmlns="http://java.sun.com/xml/ns/persistence"
 3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4     xsi:schemaLocation="http://java.sun.com/xml/ns/persistence 
 5     http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
 6   <persistence-unit name="jun" transaction-type="RESOURCE_LOCAL">
 7       <provider>org.hibernate.ejb.HibernatePersistence</provider>
 8     <properties>
 9          <property name="hibernate.dialect" 
10              value="org.hibernate.dialect.MySQLDialect"/><!--數據庫方言-->
11          <property name="hibernate.connection.driver_class" 
12              value="com.mysql.jdbc.Driver"/><!--數據庫驅動類-->
13          <property name="hibernate.connection.username" value=""/><!--數據庫用戶名-->
14          <property name="hibernate.connection.password" value=""/>
15          <property name="hibernate.connection.url" 
16              value="jdbc:mysql://localhost:3306/mytest;"/><!--數據庫鏈接URL-->
17          <property name="hibernate.max_fetch_depth" value="3"/><!--外鏈接抓取樹的最大深度 -->
18          <property name="hibernate.hbm2ddl.auto" value="update"/><!-- 自動輸出schema建立DDL語句 -->
19          <property name="hibernate.jdbc.fetch_size" value="18"/><!-- JDBC的獲取量大小 -->
20          <property name="hibernate.jdbc.batch_size" value="10"/><!-- 開啓Hibernate使用JDBC2的批量更新功能  -->
21          <property name="hibernate.show_sql" value="true"/><!-- 在控制檯輸出SQL語句 -->
22       </properties>
23   </persistence-unit>
24 </persistence>
相關文章
相關標籤/搜索