GVKun编程网logo

session.connection()在Hibernate上已弃用?(session connection)

19

如果您对session.connection和在Hibernate上已弃用?感兴趣,那么这篇文章一定是您不可错过的。我们将详细讲解session.connection的各种细节,并对在Hibernat

如果您对session.connection在Hibernate上已弃用?感兴趣,那么这篇文章一定是您不可错过的。我们将详细讲解session.connection的各种细节,并对在Hibernate上已弃用?进行深入的分析,此外还有关于Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when ...、ClassNotFoundException:组织hibernate.collection.PersistentSet + Hibernate 5.4、Connection cannot be null when ''hibernate.dialect''、Could not open Hibernate Session for transaction; nested exception is org.hibernate.TransactionEx...的实用技巧。

本文目录一览:

session.connection()在Hibernate上已弃用?(session connection)

session.connection()在Hibernate上已弃用?(session connection)

我们需要能够获得java.sql.Connectionhibernate会话的关联。没有其他连接可用,因为此连接可能与正在运行的事务关联。

如果现在不建议使用session.connection(),我应该怎么做?

答案1

小编典典

现在,您必须使用Work API:

session.doWork(    new Work() {        public void execute(Connection connection) throws SQLException         {             doSomething(connection);         }    });

或者,在Java 8+中:

session.doWork(connection -> doSomething(connection));

Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when ...

Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when ...

java.lang.IllegalStateException: Failed to load ApplicationContext

    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:125)
    at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108)
    at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:190)
    at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:132)
    at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:246)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:227)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:289)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:246)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ''entityManagerFactory'' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1778)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1105)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:744)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:391)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:312)
    at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:120)
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99)
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117)
    ... 24 more
Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:275)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:237)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214)
    at org.hibernate.id.factory.internal.DefaultIdentifierGeneratorFactory.injectServices(DefaultIdentifierGeneratorFactory.java:152)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.injectDependencies(AbstractServiceRegistryImpl.java:286)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:243)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214)
    at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.<init>(InFlightMetadataCollectorImpl.java:179)
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:119)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:904)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:935)
    at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:57)
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365)
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:390)
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:377)
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1837)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1774)
    ... 39 more
Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when ''hibernate.dialect'' not set
    at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:100)
    at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:54)
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:137)
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35)
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:94)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263)
    ... 56 more

第一次使用 springboot+jpa 进行操作数据库,刚启动就爆出来异常:

应该在 yml 配置文件中加上:

spring:
   jpa:
    show-sql: true
    hibernate:
      ddl-auto: create
    database-platform: org.hibernate.dialect.PostgreSQLDialect

 

ClassNotFoundException:组织hibernate.collection.PersistentSet + Hibernate 5.4

ClassNotFoundException:组织hibernate.collection.PersistentSet + Hibernate 5.4

如何解决ClassNotFoundException:组织hibernate.collection.PersistentSet + Hibernate 5.4?

我们正在从3级迁移到5.4版。进行所有更改后,模块运行正常,因此我合并了其他修复程序的代码。

发布此消息后,我收到一些正在处理的消息的奇怪异常。

试图找出根本原因,但无法找出为什么要引用休眠3类。。我们发送的对象具有一对多关系

我们的应用程序正在从JMS队列中读取消息,在下面,尽管没有使用过此类,但它引发了异常

Serializable obj =((ObjectMessage) message).getobject()

例外:抱歉,无法添加整个跟踪

Weblogic.jms.common.JMSException[JMSClientExceptions:055115]Error deserializing an object
. 
. 
. 
Caused By: java.lang.classNotFoundException: org hibernate.collection.PersistentSet

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

Connection cannot be null when ''hibernate.dialect''

Connection cannot be null when ''hibernate.dialect''

使用 hibernate4 时,配置文件里明明配了 <property name="dialect">org.hibernate.dialect.MySQLDialect</property>,运行时就是报错 Connection cannot be null when ''hibernate.dialect'' not set

后来在网上发现:

错误在于以下红色代码:
static{
        try{
            Configuration config = new Configuration();
            config.addClass(ProductInfoVo.class);
            sessionFactory = config.buildSessionFactory();
        }catch(MappingException e){
            e.printStackTrace();
        }catch(HibernateException e){
            e.printStackTrace();
        }
    }
以上代码只有按下面写才对:
static{
        try{
            Configuration config = new Configuration().configure();
            config.addClass(ProductInfoVo.class);
            sessionFactory = config.buildSessionFactory();
        }catch(MappingException e){
            e.printStackTrace();
        }catch(HibernateException e){
            e.printStackTrace();
        }
    }

Could not open Hibernate Session for transaction; nested exception is org.hibernate.TransactionEx...

Could not open Hibernate Session for transaction; nested exception is org.hibernate.TransactionEx...

Linuxmysql修改连接超时wait_timeout

 

1,首先:

show variables like ''%timeout%''

 

显示结果:

 

+-----------------------------+----------+

| Variable_name               | Value    |

+-----------------------------+----------+

| connect_timeout             | 10       |

| delayed_insert_timeout      | 300      |

| innodb_flush_log_at_timeout | 1        |

| innodb_lock_wait_timeout    | 50       |

| innodb_rollback_on_timeout  | OFF      |

| interactive_timeout         | 28800    |

| lock_wait_timeout           | 31536000 |

| net_read_timeout            | 30       |

| net_write_timeout           | 60       |

| rpl_stop_slave_timeout      | 31536000 |

| slave_net_timeout           | 3600     |

| wait_timeout                | 28800    |

+-----------------------------+----------+

12 rows in set (0.00 sec)

 

其中有用的是: interactive_timeout  wait_timeout  28800,默认为8小时设置;

 

一般线上的环境中mysql中连接时间设置为7天即可;

 

2,其次:

执行命令:       set  interactive_timeout=604800

 

                  set  wait_timeout=604800

 

最后:执行show variables like ''%timeout%'';看看执行成功没有,显示结果为:

 

+-----------------------------+----------+

| Variable_name               | Value    |

+-----------------------------+----------+

| connect_timeout             | 10       |

| delayed_insert_timeout      | 300      |

| innodb_flush_log_at_timeout | 1        |

| innodb_lock_wait_timeout    | 50       |

| innodb_rollback_on_timeout  | OFF      |

| interactive_timeout         | 604800   |

| lock_wait_timeout           | 31536000 |

| net_read_timeout            | 30       |

| net_write_timeout           | 60       |

| rpl_stop_slave_timeout      | 31536000 |

| slave_net_timeout           | 3600     |

| wait_timeout                | 604800   |

+-----------------------------+----------+

12 rows in set (0.00 sec)

 

表明执行成功了。。。

今天关于session.connection在Hibernate上已弃用?的分享就到这里,希望大家有所收获,若想了解更多关于Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when ...、ClassNotFoundException:组织hibernate.collection.PersistentSet + Hibernate 5.4、Connection cannot be null when ''hibernate.dialect''、Could not open Hibernate Session for transaction; nested exception is org.hibernate.TransactionEx...等相关知识,可以在本站进行查询。

本文标签: