亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

線程“主”javax.persistence.PersistenceException 中的異常:

線程“主”javax.persistence.PersistenceException 中的異常:

慕少森 2022-05-21 20:39:10
我正在使用帶有 orcale 12c 和 java 9 的休眠 5 當我執行此代碼錯誤時發生休眠無法執行語句我在 Hibernate 編寫了簡單的程序并捕獲了一堆異常。我無法找出到底出了什么問題。我有三個班級——學生、主班和hibernate.cfg、xml。這是非常簡單的休眠代碼,只涉及一個類,即學生類學生.JAVApackage 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 + "]";    }}
查看完整描述

3 回答

?
繁華開滿天機

TA貢獻1816條經驗 獲得超4個贊

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 屬性注釋您的實體類我看到該行在您的代碼中已注釋



查看完整回答
反對 回復 2022-05-21
?
慕哥9229398

TA貢獻1877條經驗 獲得超6個贊

就我而言,當有人使用最新版本的休眠時會生成此錯誤。

為了解決它,只需轉到hibernate.cfg.xml文件并根據您的版本更改方言。就我而言,我在 MySQL Workbench 中使用版本 5。

休眠.cfg.xml

<property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>

唯一完成的更改是:

<property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>

<property name="dialect">org.hibernate.dialect.MySQLDialect</property>


查看完整回答
反對 回復 2022-05-21
?
Qyouu

TA貢獻1786條經驗 獲得超11個贊

我遇到了同樣的問題-此錯誤是因為您的依賴項彼此不兼容。


Use the below dependencies and the error should be gone. 


<dependencies>

    <dependency>

        <groupId>org.hibernate</groupId>

        <artifactId>hibernate-agroal</artifactId>

        <version>5.3.15.Final</version>

        <type>pom</type>

    </dependency>

    <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->

    <dependency>`enter code here`

        <groupId>mysql</groupId>

        <artifactId>mysql-connector-java</artifactId>

        <version>8.0.15</version>

    </dependency>

     <!--https://mvnrepository.com/artifact/org.hibernate/antlr-->

    <dependency>

        <groupId>org.hibernate</groupId>

        <artifactId>antlr</artifactId>

        <version>2.7.5H3</version>

    </dependency>

    <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->

    <dependency>

        <groupId>org.hibernate</groupId>

        <artifactId>hibernate-core</artifactId>

        <version>5.4.10.Final</version>

    </dependency>

    <!-- https://mvnrepository.com/artifact/org.hsqldb/hsqldb -->

    <dependency>

        <groupId>org.hsqldb</groupId>

        <artifactId>hsqldb</artifactId>

        <version>2.4.0</version>

        <scope>test</scope>

    </dependency>

    <!-- https://mvnrepository.com/artifact/com.fasterxml/classmate -->

    <dependency>

        <groupId>com.fasterxml</groupId>

        <artifactId>classmate</artifactId>

        <version>1.3.1</version>

    </dependency>

    <!-- https://mvnrepository.com/artifact/dom4j/dom4j -->

    <dependency>

        <groupId>dom4j</groupId>

        <artifactId>dom4j</artifactId>

        <version>1.6.1</version>

    </dependency>

    <!-- https://mvnrepository.com/artifact/javax.el/el-api -->

    <dependency>

        <groupId>javax.el</groupId>

        <artifactId>el-api</artifactId>

        <version>2.2</version>

    </dependency>

    <!-- https://mvnrepository.com/artifact/org.apache.geronimo.specs/geronimo-jta_1.1_spec -->

    <dependency>

        <groupId>org.apache.geronimo.specs</groupId>

        <artifactId>geronimo-jta_1.1_spec</artifactId>

        <version>1.1.1</version>

    </dependency>

    <!-- https://mvnrepository.com/artifact/org.jboss/jandex -->

    <dependency>

        <groupId>org.jboss</groupId>

        <artifactId>jandex</artifactId>

        <version>2.1.2.Final</version>

    </dependency>

    <!-- https://mvnrepository.com/artifact/javassist/javassist -->

    <dependency>

        <groupId>javassist</groupId>

        <artifactId>javassist</artifactId>

        <version>3.12.1.GA</version>

    </dependency>

    <!-- https://mvnrepository.com/artifact/javax.activation/javax.activation-api -->

    <dependency>

        <groupId>javax.activation</groupId>

        <artifactId>javax.activation-api</artifactId>

        <version>1.2.0</version>

    </dependency>

    <!-- https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-core -->

    <dependency>

        <groupId>com.sun.xml.bind</groupId>

        <artifactId>jaxb-core</artifactId>

        <version>2.3.0.1</version>

    </dependency>

    <!-- https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-impl -->

    <dependency>

        <groupId>com.sun.xml.bind</groupId>

        <artifactId>jaxb-impl</artifactId>

        <version>2.3.2</version>

    </dependency>

    <!-- https://mvnrepository.com/artifact/javax.persistence/javax.persistence-api -->

    <dependency>

        <groupId>javax.persistence</groupId>

        <artifactId>javax.persistence-api</artifactId>

        <version>2.2</version>

    </dependency>

    <!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api -->

    <dependency>

        <groupId>javax.xml.bind</groupId>

        <artifactId>jaxb-api</artifactId>

        <version>2.3.1</version>

    </dependency>

    <!-- https://mvnrepository.com/artifact/org.glassfish.jaxb/jaxb-runtime -->

    <dependency>

        <groupId>org.glassfish.jaxb</groupId>

        <artifactId>jaxb-runtime</artifactId>

        <version>2.3.1</version>

    </dependency>

    <!-- https://mvnrepository.com/artifact/org.jboss.logging/jboss-logging -->

    <dependency>

        <groupId>org.jboss.logging</groupId>

        <artifactId>jboss-logging</artifactId>

        <version>3.3.2.Final</version>

    </dependency>

    <!-- https://mvnrepository.com/artifact/org.jboss.spec.javax.transaction/jboss-transaction-api_1.2_spec -->

    <dependency>

        <groupId>org.jboss.spec.javax.transaction</groupId>

        <artifactId>jboss-transaction-api_1.2_spec</artifactId>

        <version>1.1.1.Final</version>

    </dependency>

    <!-- https://mvnrepository.com/artifact/org.jvnet.staxex/stax-ex -->

    <dependency>

        <groupId>org.jvnet.staxex</groupId>

        <artifactId>stax-ex</artifactId>

        <version>1.8</version>

    </dependency>

    <!-- https://mvnrepository.com/artifact/org.glassfish.jaxb/txw2 -->

    <dependency>

        <groupId>org.glassfish.jaxb</groupId>

        <artifactId>txw2</artifactId>

        <version>2.3.1</version>

    </dependency>

</dependencies>



查看完整回答
反對 回復 2022-05-21
  • 3 回答
  • 0 關注
  • 150 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號