JPA Hibernate配置问题

时间:2019-01-07 22:16:09

标签: java hibernate jpa

我一直试图在不同的环境中以多种方式配置JPA,但我正变得越来越绝望。谁能告诉我我想念的东西吗?

例外:

Exception in thread "main" org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
etc.
Caused by: org.hibernate.boot.registry.selector.spi.StrategySelectionException: Unable to resolve name [org.hibernate.dialect.MySSQL5Dialect] as strategy [org.hibernate.dialect.Dialect]
etc...
    ... 37 more
Caused by: org.hibernate.boot.registry.classloading.spi.ClassLoadingException: Unable to load class [org.hibernate.dialect.MySSQL5Dialect]
etc...
    ... 47 more
Caused by: java.lang.ClassNotFoundException: Could not load requested class : org.hibernate.dialect.MySSQL5Dialect


etc...
    ... 48 more

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="BoatsPU" transaction-type="RESOURCE_LOCAL">

        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
        <class>com.dante.jpa.Boat</class>

        <properties>

            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/boats" />
            <property name="javax.persistence.jdbc.password" value="4dm1n" />
            <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
            <property name="javax.persistence.jdbc.user" value="boats_admin" />
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySSQL5Dialect"/>
            <property name="hibernate.hbm2ddl.auto" value="create.drop"/>

        </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>com.dante</groupId>
    <artifactId>JPATest2</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <dependencies>
        <!-- JPA implementation. -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>5.4.0.Final</version>
        </dependency>

        <!-- Driver for desired SQL server. -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.13</version>
        </dependency>

    </dependencies>
</project>

整个应用当前由Main以及交易类和模型类组成。

我什至无法粘贴所有异常代码,因为stackoverflow表示我必须添加更多详细信息-_-

2 个答案:

答案 0 :(得分:0)

类名是MySQL5Dialect,而不是MySSQL5Dialect

答案 1 :(得分:0)

java.lang.ClassNotFoundException表示您的类名称错误。确切的名称是MySQL5InnoDBDialect。 因此,您应该将xml更改为:

<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>