简体   繁体   English

请帮我找到这个错误。 我正在使用 hibernate 5.6.4 和 MySQL 8.0.29

[英]Please help me to Find this error. I'm using hibernate 5.6.4 with MySQL 8.0.29

error错误

Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute statement at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:154) at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:181) at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:188) at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1406) at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:493) at org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:3285) Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute statement at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:154) at org.hibernate.internal.ExceptionConverterImpl. convert(ExceptionConverterImpl.java:181) at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:188) at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1406) at org.hibernate.internal.SessionImpl .managedFlush(SessionImpl.java:493) 在 org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.Z93F725A072423FE1C886ZD43) at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2420) at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:449) at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.beforeCompletionCallback(JdbcResourceLocalTransactionCoordinatorImpl.java:183) at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.access$300(JdbcResourceLocalTransactionCoordinatorImpl.java:40) at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalT at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2420) at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:449) at org.hibernate.resource.transaction.backend.jdbc .internal.JdbcResourceLocalTransactionCoordinatorImpl.beforeCompletionCallback(JdbcResourceLocalTransactionCoordinatorImpl.java:183) at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.access$300(JdbcResourceLocalTransactionCoordinatorImpl.java:40) at org.hibernate.resource.transaction.backend. jdbc.internal.JdbcResourceLocalT ransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:281) at org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:101) at com.tapacad.application.Program2.main(Program2.java:34) Caused by: org.hibernate.exception.SQLGrammarException: could not execute statement at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:63) at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:37) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.Z93F725A07423FE1 ransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:281) at org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:101) at com.tapacad.application.Program2.main(Program2.java:34) Caused by: org.hibernate.exception.SQLGrammarException: could not execute statement at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:63) at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java :37) 在 org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.Z93F725A07423FE1 C889F448B33D21F46Z:113) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99) at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:200) at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:46) at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3375) at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3908) at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.Z93F725A07423FE1C88 C889F448B33D21F46Z:113) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99) at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:200) at org.hibernate .engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:46) at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3375) at org.hibernate.persister.entity.AbstractEntityPersister.insert (AbstractEntityPersister.java:3908) 在 org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.Z93F725A07423FE1C88 9F448B33D21F46Z:107) at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:604) at org.hibernate.engine.spi.ActionQueue.lambda$executeActions$1(ActionQueue.java:478) at java.base/java.util.LinkedHashMap.forEach(LinkedHashMap.java:721) at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:475) at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:344) at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:40) at org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(Ev 9F448B33D21F46Z:107) at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:604) at org.hibernate.engine.spi.ActionQueue.lambda$executeActions$1(ActionQueue.java:478) at java.base/ java.util.LinkedHashMap.forEach(LinkedHashMap.java:721) at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:475) at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java: 344) at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:40) at org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(Ev entListenerGroupImpl.java:107) at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1402)... 9 more Caused by: java.sql.SQLSyntaxErrorException: Table 'hibernatedb.student' doesn't exist at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120) at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:916) at Z4D236D9A2D102C5F entListenerGroupImpl.java:107) at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1402)... 9 more Caused by: java.sql.SQLSyntaxErrorException: Table 'hibernatedb.student' doesn't exist at com. mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120) at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) at com.mysql.cj.jdbc.ClientPreparedStatement.在 Z4D236D9A2D102C5F 执行内部(ClientPreparedStatement.java:916) E6AD1C50DA4BEC50Z.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1061) at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1009) at com.mysql.cj.jdbc.ClientPreparedStatement.executeLargeUpdate(ClientPreparedStatement.java:1320) at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdate(ClientPreparedStatement.java:994) at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnIm E6AD1C50DA4BEC50Z.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1061) at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1009) at com.mysql.cj.jdbc.ClientPreparedStatement.executeLargeUpdate( ClientPreparedStatement.java:1320) at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdate(ClientPreparedStatement.java:994) at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnIm pl.java:197)... 21 more pl.java:197)... 21 更多

Student.java学生.java

package com.tapacad.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "student")
public class Student {
    
    // Attributes
    @Id
    @Column(name = "roll")
    private int roll;
    
    @Column(name = "name")
    private String name;
    
    @Column(name = "email")
    private String email;
    
    @Column(name = "marks")
    private int marks;
    
    // Constructor
    public Student() {
        
    }

    public Student(int roll, String name, String email, int marks) {
        super();
        this.roll = roll;
        this.name = name;
        this.email = email;
        this.marks = marks;
    }

    // Setters and Getters
    
    public int getRoll() {
        return roll;
    }

    public void setRoll(int roll) {
        this.roll = roll;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }
    
    public int getMarks() {
        return marks;
    }

    public void setMarks(int marks) {
        this.marks = marks;
    }
    
}

Program2.java程序2.java

package com.tapacad.application;

import java.io.Serializable;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

import com.tapacad.model.Student;

public class Program2 {

    public static void main(String[] args) {
        
        Session session = null;
        SessionFactory sessionFactory = null;
        
        try {
            Configuration config = new Configuration();
            config.configure();
            config.addAnnotatedClass(Student.class);
            
            sessionFactory = config.buildSessionFactory();
            session = sessionFactory.openSession();
            
            // Create Transaction
            Transaction transaction = session.beginTransaction();
            
            // CRUD Operation
            Student s = new Student(1,"Alex","alex@gmail.com",97);
            session.save(s);
            
            transaction.commit();
        }
        finally{
            session.close();
            sessionFactory.close();
        }
        
    }

}

hibernate.cfg.xml hibernate.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
    
    
    
    <hibernate-configuration>
        <session-factory>
            <property name = "hibernate.connection.driver.class">com.mysql.cj.jdbc.Driver</property>
            <property name = "hibernate.connection.url">jdbc:mysql://localhost:3306/hibernatedb</property>
            <property name = "hibernate.connection.username">root</property>
            <property name = "hibernate.connection.password">mysql@123</property>
            <property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>
            <property name = "hibernate.hbm2dll.auto">update</property>
            <property name = "show_sql">update</property>
        
        </session-factory>
        
        
    </hibernate-configuration>

Typo alert!错字警告!

Hibernate property name hbm2dll typo. Hibernate 属性名称hbm2dll拼写错误。

hbm2ddl is the correct one. hbm2ddl是正确的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我收到以下运行时错误。 请帮我找出原因 - I'm getting the following runtime error. Please help me figure out why 当我启动Web Start应用程序时,出现以下错误。 请帮我 - When I launch an web start application i am geteng the following error. Please help me 1772年加勒比海在线法官给出时间限制超出错误。 请帮我解释为什么我的算法花了这么长时间 - 1772 of Caribbean online judge giving a time limit exceeded error. please help me find why is my algorithm taking so long 我的第一个休眠程序出现错误,请帮助我解决错误 - I am getting error for my first hibernate program, please help me to resolve the erros 我正在尝试在 Java 中呈现一个蓝色方块,但出现 IllegalStateException 错误。 有人能帮我吗? - I'm Trying To Render A Blue Square In Java But I Am Getting A IllegalStateException Error. Can Someone Help Me? 遇到找不到或无法加载主类错误的情况,有人可以帮助我修复该错误吗? 我是Java新手 - Getting a could not find or load main class error, can anyone help me fix it? I'm new to java 我尝试制作一个 Tablayout 但它有一个错误请帮帮我 - I try to make A Tablayout But its have an error Please Help me 使用IBM Sterling V9.3(包括ISCCS)启动jboss服务器时,即时通讯收到以下错误。 请帮我 - While starting the jboss server with IBM Sterling V9.3 (ISCCS included), im getting the below error. please help me with it 我正在尝试使用 XML 运行第一个 Spring 程序,但出现以下错误。 我是新手,请指导我 - I am trying to run this first Spring program using XML and I am getting following error. I am novice in this, Please guide me 有人可以帮我解决此代码,我是Java新手 - Could someone please help me fix this code, I'm new to java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM