hibernate:hibernate.hbm2ddl.auto update但错误消息是表已经存在?

ljsrvy3e  于 2021-06-30  发布在  Java
关注(0)|答案(0)|浏览(156)

基础
休眠:5.4.25.5
mysql:5.7 i 用户休眠orm以获得持久性,但我遇到了一个问题:

Map<String, Object> properties     = sessionFactory.getProperties();
        properties.put("hibernate.connection.username", username);
        properties.put("hibernate.connection.password", password);
        SessionFactory currentSessionFactory = null;
        try {
            GroovyClassLoader groovyClassLoader = getGroovyClassLoader(connId);
            StandardServiceRegistry standardServiceRegistry = new StandardServiceRegistryBuilder()
                    .applySettings(properties)
                    .addService(ClassLoaderService.class, new ClassLoaderServiceImpl(groovyClassLoader))
                    .build();

            MetadataSources metadataSources = new MetadataSources(standardServiceRegistry);
            for (Clazz clazz : classList) {
                Class<?> cls = clazz.getClazz();
                metadataSources = metadataSources.addAnnotatedClass(cls);
            }
            Metadata     metadata = metadataSources.buildMetadata();
            currentSessionFactory = metadata.buildSessionFactory();

以下是我的设置:

Properties p = new Properties();
            p.put("hibernate.connection.driver_class", connConfig.getDriver());
            p.put("hibernate.connection.url", connConfig.getUrl());
            p.put("hibernate.connection.username", connConfig.getUsername());
            p.put("hibernate.connection.password", connConfig.getPassword());
            p.put("hibernate.dialect", connConfig.getDialect());
            p.put("hibernate.hbm2ddl.auto", "update");
            p.put("show_sql", true);
            p.put("format_sql", false);
            p.put("current_session_context_class", "thread");
            p.put("hibernate.connection.pool_size", 100);
            p.put("hibernate.connection.isolation", 2);

但这里有一条错误消息:表已经存在。为什么设置“hibernate.hbm2ddl”。auto:update“不按预期工作?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题