Я использую Hibernate 5.4.15 и mysql 8. когда я добавляю только класс ученика в файл конфигурации, это нормально. Но больше файлов получают ошибки? - PullRequest
0 голосов
/ 06 мая 2020

Я новичок и пытаюсь изучить Hibernate. Я использую Hibernate 5.4.15 и mysql 8. когда я добавляю только класс ученика в файл конфигурации, это нормально. Но когда я добавляю более одного, возникают ошибки?

**

    May 06, 2020 6:34:40 AM org.hibernate.Version logVersion
    INFO: HHH000412: Hibernate ORM core version 5.4.15.Final
    May 06, 2020 6:34:40 AM org.hibernate.annotations.common.reflection.java.JavaReflectionManager 
    INFO: HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
    May 06, 2020 6:34:41 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
    WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
    May 06, 2020 6:34:41 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
    INFO: HHH10001005: using driver [com.mysql.cj.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/jlcdb]
    May 06, 2020 6:34:41 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
    INFO: HHH10001001: Connection properties: {user=root, password=****}
    May 06, 2020 6:34:41 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
    INFO: HHH10001003: Autocommit mode: false
    May 06, 2020 6:34:41 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl$PooledConnections 
    INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
    May 06, 2020 6:34:44 AM org.hibernate.dialect.Dialect 
    INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQL8Dialect
    May 06, 2020 6:34:47 AM org.hibernate.AssertionFailure 
    ERROR: HHH000099: an assertion failure occurred (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session): org.hibernate.AssertionFailure: Table jlcdb.students not found
    May 06, 2020 6:34:47 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl$PoolState stop
    INFO: HHH10001008: Cleaning up connection pool [jdbc:mysql://localhost:3306/jlcdb]
    java.lang.NullPointerException at com.akhilesh.Lab04B.main(Lab04B.java:15)

**

======================== =========== Это мой файл конфигурации ================================== ======

public class JDBCUtil {

    static SessionFactory sessionFactory = null;
    static {

        try {
            Configuration cfg = new Configuration();
            Properties props = new Properties();
            props.put(Environment.DRIVER, "com.mysql.cj.jdbc.Driver");
            props.put(Environment.URL, "jdbc:mysql://localhost:3306/jlcdb");
            props.put(Environment.USER, "root");
            props.put(Environment.PASS, "akhilesh");
            props.put(Environment.DIALECT, "org.hibernate.dialect.MySQL8Dialect");
            props.put(Environment.SHOW_SQL, "true");
            props.put(Environment.HBM2DDL_AUTO, "update");
            props.put(Environment.CURRENT_SESSION_CONTEXT_CLASS, "thread");

            cfg.setProperties(props);

            cfg.addAnnotatedClass(Student.class);//one is working fine
            cfg.addAnnotatedClass(CurrentStudent.class);
            cfg.addAnnotatedClass(OldStudent.class);
            cfg.addAnnotatedClass(WeekdayStudent.class);
            cfg.addAnnotatedClass(WeekendStudent.class);

            StandardServiceRegistryBuilder ssrbuilder = new StandardServiceRegistryBuilder();
            ServiceRegistry sr = ssrbuilder.applySettings(cfg.getProperties()).build();

            sessionFactory = cfg.buildSessionFactory(sr);
        }catch(Exception e) {

        }
    }
    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...