jpa Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
程序员文章站
2022-04-12 21:02:46
...
学习jpa 普通 的java项目当中在pom的文件当中根据视频添加了jar包以及配置文件,启动时报错
主要错误为
Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
java.lang.UnsupportedOperationException: The application must supply JDBC connections
Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
根据提示信息可能是没有设置 hibernate.dialect 以及数据库连接persistence.xml文件配置出问题
更改配置
<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
<!-- 持久化单元名称
transaction-type
JTA分布式管理 分表
RESOURCE_LOCAL 本地事物管理
-->
<persistence-unit name="myJpa" transaction-type="RESOURCE_LOCAL">
<!-- jps实现方式 -->
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<!-- 数据库信息 配置信息等-->
<properties>
<!-- 报错 可能不同的版本或者不同的数据库连接问题 -->
<!-- <property name="bytecode.persistence.jdbc.user" value="root"/>-->
<!-- <property name="bytecode.persistence.jdbc.password" value="root"/>-->
<!-- <property name="bytecode.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>-->
<!-- <property name="bytecode.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/jpa"/>-->
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/jpa"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.username" value="root"/>
<property name="hibernate.connection.password" value="root"/>
<!-- 配置jpa实现方式(hibernate)实现方式
hibernate.show_sql 显示sql
hibernate.hbm2ddl.auto create 自动创建数据表,删除之前的
update 有则追加 没有就创建
none 只添加 没有表报错
-->
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
<!-- 1.如果配置文件格式为application.properties,在配置文件中设置以下代码即可:
spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect
2.如果配置文件格式为application.xml,则在JPA配置中设置以下代码:
database-platform: org.hibernate.dialect.MySQL5Dialect
-->
</properties>
</persistence-unit>
</persistence>
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cn.itcast</groupId>
<artifactId>jpa-day1</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.hibernate.version>5.0.7.Final</project.hibernate.version>
</properties>
<dependencies>
<!-- junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- hibernate对jpa的支持包 -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${project.hibernate.version}</version>
</dependency>
<!-- c3p0 -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>${project.hibernate.version}</version>
</dependency>
<!-- log日志 -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<!-- Mysql and MariaDB -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.23.1-GA</version>
</dependency>
</dependencies>
</project>
推荐阅读
-
hibernate Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
-
springboot 连接数据库报错 Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnviron
-
Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
-
jpa Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
-
org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine
-
JPA org.hibernate.service.spi.ServiceException: Unable to create requested service [xxx]问题解决
-
Hibernate:Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
-
hibernate5配置Druid遇到Unable to create requested service [org.hibernate.engine.jdbc.connections.spi.Con
-
解决打包jar启动报错Unable to create requested service[org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]问题
-
hibernate入门Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]