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

检查一下 数据源 配置, 看你的异常应该是 使用 JTA 事物 ,容器没有实例化 EntityManager 

 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>

 

posted on 2016-11-30 16:11  Sharpest  阅读(4425)  评论(0编辑  收藏  举报