线程“主”javax.persistence.PersistenceException 中的异常:

我正在使用带有 orcale 12c 和 java 9 的休眠 5 当我执行此代码错误时发生休眠无法执行语句


我在 Hibernate 编写了简单的程序并捕获了一堆异常。


我无法找出到底出了什么问题。


我有三个班级——学生、主班和hibernate.cfg、xml。


这是非常简单的休眠代码,只涉及一个类,即学生类


学生.JAVA

package hibernate.demo.entity;


import javax.persistence.Column;

import javax.persistence.Entity;

import javax.persistence.GeneratedValue;

import javax.persistence.GenerationType;

import javax.persistence.Id;

import javax.persistence.Table;


@Entity

//@Table(name="student")

public class Student {


    @Id

//  @GeneratedValue(strategy=GenerationType.AUTO)

    @Column(name="id")

    private int id;


    @Column(name="first_Name")

    private String firstName;


    @Column(name="last_Name")

    private String lastName;


    @Column(name="email")

    private String email;


    public Student() {


    }

    public Student(String firstName, String lastName, String email) {

        super();

        this.firstName = firstName;

        this.lastName = lastName;

        this.email = email;

    }

    public int getId() {

        return id;

    }

    public void setId(int id) {

        this.id = id;

    }

    public String getFirstName() {

        return firstName;

    }

    public void setFirstName(String firstName) {

        this.firstName = firstName;

    }

    public String getLastName() {

        return lastName;

    }

    public void setLastName(String lastName) {

        this.lastName = lastName;

    }

    public String getEmail() {

        return email;

    }

    public void setEmail(String email) {

        this.email = email;

    }

    @Override

    public String toString() {

        return "Student [id=" + id + ", firstName=" + firstName + ", lastName=" + lastName + ", email=" + email + "]";

    }


}


慕少森
浏览 119回答 3
3回答

繁华开满天机

stacktrace 中的错误清楚地表明该表未找到。Caused by: java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist因此,您可以在 oracle db 中的模式中创建一个表,或者告诉 hibernate 在创建会话工厂时创建表。您可以在休眠配置文件中包含以下属性<property name="hibernate.hbm2ddl.auto" value="create"/>所以hibernate会为你创建一个表。此外,您需要使用 @Table 属性注释您的实体类我看到该行在您的代码中已注释

慕哥9229398

就我而言,当有人使用最新版本的休眠时会生成此错误。为了解决它,只需转到hibernate.cfg.xml文件并根据您的版本更改方言。就我而言,我在 MySQL Workbench 中使用版本 5。休眠.cfg.xml:<property&nbsp;name="dialect">org.hibernate.dialect.MySQL5Dialect</property>唯一完成的更改是:<property&nbsp;name="dialect">org.hibernate.dialect.MySQL5Dialect</property>从<property&nbsp;name="dialect">org.hibernate.dialect.MySQLDialect</property>

Qyouu

我遇到了同样的问题-此错误是因为您的依赖项彼此不兼容。Use the below dependencies and the error should be gone.&nbsp;<dependencies>&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.hibernate</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>hibernate-agroal</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>5.3.15.Final</version>&nbsp; &nbsp; &nbsp; &nbsp; <type>pom</type>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->&nbsp; &nbsp; <dependency>`enter code here`&nbsp; &nbsp; &nbsp; &nbsp; <groupId>mysql</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>mysql-connector-java</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>8.0.15</version>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; &nbsp;<!--https://mvnrepository.com/artifact/org.hibernate/antlr-->&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.hibernate</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>antlr</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>2.7.5H3</version>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.hibernate</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>hibernate-core</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>5.4.10.Final</version>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <!-- https://mvnrepository.com/artifact/org.hsqldb/hsqldb -->&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.hsqldb</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>hsqldb</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>2.4.0</version>&nbsp; &nbsp; &nbsp; &nbsp; <scope>test</scope>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <!-- https://mvnrepository.com/artifact/com.fasterxml/classmate -->&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>com.fasterxml</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>classmate</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>1.3.1</version>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <!-- https://mvnrepository.com/artifact/dom4j/dom4j -->&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>dom4j</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>dom4j</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>1.6.1</version>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <!-- https://mvnrepository.com/artifact/javax.el/el-api -->&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>javax.el</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>el-api</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>2.2</version>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <!-- https://mvnrepository.com/artifact/org.apache.geronimo.specs/geronimo-jta_1.1_spec -->&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.apache.geronimo.specs</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>geronimo-jta_1.1_spec</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>1.1.1</version>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <!-- https://mvnrepository.com/artifact/org.jboss/jandex -->&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.jboss</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>jandex</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>2.1.2.Final</version>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <!-- https://mvnrepository.com/artifact/javassist/javassist -->&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>javassist</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>javassist</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>3.12.1.GA</version>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <!-- https://mvnrepository.com/artifact/javax.activation/javax.activation-api -->&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>javax.activation</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>javax.activation-api</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>1.2.0</version>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <!-- https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-core -->&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>com.sun.xml.bind</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>jaxb-core</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>2.3.0.1</version>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <!-- https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-impl -->&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>com.sun.xml.bind</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>jaxb-impl</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>2.3.2</version>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <!-- https://mvnrepository.com/artifact/javax.persistence/javax.persistence-api -->&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>javax.persistence</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>javax.persistence-api</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>2.2</version>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api -->&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>javax.xml.bind</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>jaxb-api</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>2.3.1</version>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <!-- https://mvnrepository.com/artifact/org.glassfish.jaxb/jaxb-runtime -->&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.glassfish.jaxb</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>jaxb-runtime</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>2.3.1</version>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <!-- https://mvnrepository.com/artifact/org.jboss.logging/jboss-logging -->&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.jboss.logging</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>jboss-logging</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>3.3.2.Final</version>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <!-- https://mvnrepository.com/artifact/org.jboss.spec.javax.transaction/jboss-transaction-api_1.2_spec -->&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.jboss.spec.javax.transaction</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>jboss-transaction-api_1.2_spec</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>1.1.1.Final</version>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <!-- https://mvnrepository.com/artifact/org.jvnet.staxex/stax-ex -->&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.jvnet.staxex</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>stax-ex</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>1.8</version>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <!-- https://mvnrepository.com/artifact/org.glassfish.jaxb/txw2 -->&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.glassfish.jaxb</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>txw2</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>2.3.1</version>&nbsp; &nbsp; </dependency></dependencies>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java