SSH中使用getCurrentSession()获得session使用时注意事项,Hibernate,项目经验

SSH中使用getCurrentSession()获得session

 

  1. 在hibernate的配置文件中增加属性:

     

    <property name="current_session_context_class">thread</property>

    如下表红色部分

    Java代码    收藏代码
    1. <hibernate-configuration>  
    2.   
    3. <session-factory>  
    4.   
    5.    <property name="connection.username">root</property>  
    6.   
    7.    <property name="connection.url">  
    8.   
    9.     jdbc:mysql://localhost:3306/dbtest  
    10.   
    11.    </property>  
    12.   
    13.    <property name="dialect">  
    14.   
    15.     org.hibernate.dialect.MySQLDialect  
    16.   
    17.    </property>  
    18.   
    19.    <property name="myeclipse.connection.profile">dbtest</property>  
    20.   
    21.    <property name="connection.password">123456</property>  
    22.   
    23.    <property name="connection.driver_class">  
    24.   
    25.     com.mysql.jdbc.Driver  
    26.   
    27.    </property>  
    28.   
    29.    <property name="show_sql">true</property>  
    30.   
    31.   <property name="current_session_context_class">thread</property>  
    32.   
    33.    <mapping resource="com/pc386/hibernate/entity/User.hbm.xml" />  
    34.   
    35.     
    36.   
    37. </session-factory>  
    38.   
    39. </hibernate-configuration>  
    40.    

     

    在SSH中,如果把hibernate交给Spring的管理事物中,那么应该修改Spring的配置文件applicationContext.xml文件的属性,在sessionFactory的属性中增加: <prop key="current_session_context_class">thread</prop>
    Java代码    收藏代码
    1. bean id="sessionFactory"   
    2.   
    3. class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">  
    4.   
    5. <property name="dataSource">  
    6.   
    7.    <ref local="dataSource"/>  
    8.   
    9. </property>  
    10.   
    11. <property name="mappingResources">  
    12.   
    13.    <list>  
    14.   
    15.     <value>User.hbm.xml </value>  
    16.   
    17.    </list>  
    18.   
    19. </property>  
    20.   
    21. <property name="hibernateProperties">  
    22.   
    23.    <props>  
    24.   
    25.     <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>  
    26.   
    27. <!--  
    28.   
    29.     <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</prop>  
    30.   
    31. -->  
    32.   
    33.     <prop key="hibernate.current_session_context_class">thread</prop>  
    34.   
    35.    </props>  
    36.   
    37. </property>  
    38.   
    39. </bean>  
    40.    
     原文出处
  2. http://blog.youkuaiyun.com/daryl715/archive/2007/02/11/1507385.aspx
    Java代码    收藏代码
    1. No CurrentSessionContext configured!" 异常解决方案  
    2.   
    3. hibernate 老说没有配方言  
    4.   
    5. <property name="dialect">org.hibernate.dialect.MySQLDialect</property>  
    6.   
    7. 这句话明明就写在了配置文件里面,可老是没有写  
    8.   
    9. 错误如下:  
    10.   
    11. Exception in thread "main" org.hibernate.HibernateException: Hibernate Dialect must be explicitly set  
    12.   
    13. name改成"hibernate.dialect"也不行  
    14.   
    15. Hibernate-Version: 3.1.1  
    16.   
    17. mysql -Verison: 4.0.16  
    18.   
    19. 用这种方法正确  
    20.   
    21. static {  
    22.   
    23. try {  
    24.   
    25. configuration = new Configuration();  
    26.   
    27. sessionFactory = configuration.configure().buildSessionFactory();  
    28.   
    29. } catch (Throwable ex) {  
    30.   
    31. throw new ExceptionInInitializerError(ex);  
    32.   
    33. }  
    34.   
    35. }  
    36.   
    37. 这种方式会出现异常  
    38.   
    39. // static {  
    40.   
    41. // try {  
    42.   
    43. // // Create a configuration based on the properties file we've put  
    44.   
    45. // Configuration config = new Configuration();  
    46.   
    47. // config.addClass(Customer.class).addClass(Order.class);  
    48.   
    49. // // Get the session factory we can use for persistence  
    50.   
    51. // sessionFactory = config.buildSessionFactory();  
    52.   
    53. // } catch (Exception e) {  
    54.   
    55. // e.printStackTrace();  
    56.   
    57. // }  
    58.   
    59. // }  
    60.   
    61. 第二种方式是针对使用properties文件配置hiernate的写法,使用hibernate.cfg.xml应使用第一种调用方式  
    62.   
    63. 或者在hibernate.cfg.xml中加入:  
    64.   
    65. <property name="current_session_context_class">thread</property>  
     http://blog.sina.com.cn/s/blog_412d58ec010005p5.html
    Java代码    收藏代码
    1. 以前单独用Hibernate2.0的时候,为了保证一个线程中每次取出的session都是一个对象,就使用官方提供的一个HibernateUtils,将第一次取出的session放入ThreadLocal中,以后每次从这里面取出的session都是一个对象,可以保证事务的正常执行。  
    2.   
    3. 后来升级到3.0,也这样延用下去,没怎么关心3.0的新特性。  
    4.   
    5. 前几天想将Hibernate加入到SPRING的事务管理中,但是我又不想使用spring提供的HibernateDaoSupport或HibernateTemplate,只想像以前那样在一个线程中的任意地方都能得到同一个session。这样就出问题了,spring管理事务的话,如果要保证当前线程内只有一个session,需要将sessionFactory传递给org.springframework.orm.hibernate3.HibernateTransactionManager,spring负责事务的开始,提交,回滚以及session的关闭,假设spring用于管理事务的session是(session1)。如果我还用HibernateUtils.getCurrentSession()方法获得session的话,得到的session却是(session2),和开始事务的session不是同一个对象,就造成session2的事务没有提交,对数据库的操作无效。  
    6.   
    7. 后来搜索到原来Hibernate3.0以后,sessionFactory多了个新的方法getCurrentSession()。我心里很高兴,这样不就解决我的问题了吗?  
    8.   
    9. 于是我就将HibernateUtils中的session=sessionFactory.openSession()方法改为了session=sessionFactory.getCurrentSession().  
    10.   
    11. 运行测试竟然错了,  
    12.   
    13. 提示什么TransactionManager出错了,上网上搜了搜,原来使用getCurrent方法必须配置事务管理,需要和jta或thread绑定。我不想用jta,当然要和线程绑定了。我在hibernate的配置文件中加入了<property name="current_session_context_class">thread</property>,又运行,还是出同样的错误。继续上网上查资料,基本没有相关资料。后来费了好大劲才发现,原来在hibernate3.0里只能和jta绑定,我copy了新的3.2的包,这下可以了。不出那个事务管理的错了,变成了org.hibernate.HibernateException: save is not valid without active transaction错误。继续搜,只有一个相关资料,说使用getCurrentSession()方法必须在事务中运行。不管查询还是更新操作都要开始事务,操作,提交事务才行。  
    14.   
    15. 可是我已经配置了让spring管理事务,为什么出这个错误?看来只有一个原因,spring在通过sessionFactory获取session时,没有调用getCurrentSession()方法。  
    16.   
    17. 自己手动加入事务的开始,提交,成功了。  
    18.   
    19. 经过多次实验,发现,只能能spring中配置sessionFactory,才能让spring管理hibernate的事务。  
    20.   
    21. <bean id="sessionFactory"  
    22.   
    23. class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">  
    24.   
    25. <property name="dataSource">  
    26.   
    27.    <ref local="dataSource"/>  
    28.   
    29. </property>  
    30.   
    31. <property name="mappingResources">  
    32.   
    33.    <list>  
    34.   
    35.     <value>User.hbm.xml </value>  
    36.   
    37.    </list>  
    38.   
    39. </property>  
    40.   
    41. <property name="hibernateProperties">  
    42.   
    43.    <props>  
    44.   
    45.     <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>  
    46.   
    47. <!--  
    48.   
    49.     <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</prop>  
    50.   
    51. -->  
    52.   
    53.     <prop key="hibernate.current_session_context_class">thread</prop>  
    54.   
    55.    </props>  
    56.   
    57. </property>  
    58.   
    59. </bean>  
    60.   
    61. 在程序中要用到session的时候,过程如下 :  
    62.   
    63. UserDAOImpl:  
    64.   
    65. {  
    66.   
    67. SessionFactory sf = [从spring中得到sessionFactory];  
    68.   
    69. Session session = sf.getCurrentSession();  
    70.   
    71. //数据库操作  
    72.   
    73. }  
    74.   
    75. 这么乱。写一下总结。  
    76.   
    77. 1. 如果想让spring帮你管理事务,只能在spring中配置SessionFactory。如果使用hibernate原有的sessionFactory,则只能自己手动管理事务。  
    78.   
    79. 2. 如果想使用sessionFactory.getCurrentSession()方法,必须配置sessionFactory和jta或thread绑定。但是hibernate3.0不支持与thread绑定,3.1以上才支持。  
    80.   
    81. 3. sessionFactory.getCurrentSession()方法取得的session,在做数据库操作时必须在事务中做,包括只读的查询,否则会报错。  
    82.    
     
新Hibernate SessionFactory().getCurrentSession()猫腻 NULL 博文链接:https://zgdkik.iteye.com/blog/1835667 立即下载

相关推荐

getCurrentSession 与 openSession() 的区别

NULL 博文链接:https://bbxyhaihua.iteye.com/blog/505085

hibernate 之 getCurrentSession() 详解

在Spring @Transactional声明式事务管理的配置中,hibernate.current_session_context_class=thread 这一句是不能加的,加了就会出错,那为什么不能加呢? 那是因为在Spring事务管理中,current Session是绑定到SpringSessionContext中的,而不是ThreadLocalSessionContext中的。

Skyline 2935

SessionFactory.getCurrentSession与openSession的区别

博文链接:https://shaqiang32.iteye.com/blog/201918

Hibernate中openSession()和getCurrentSession()方法的区别

首先它们都是通过SessionFactory构建Session对象的。 一、区别: 1. openSession 从字面上可以看得出来,是打开一个新的session对象,而且每次使用都是打开一个新的session,假如连续使用多次,则获得的session不是同一个对象,并且使用完需要调用close方法关闭session。 2. getCurrentSession ,从字面上可以看得出来,是获...

“花花”公子_龙的博客 3927

ROS——无人机ROS仿真包 rotors_simulator 编译教程

文章目录 安装wstool sudo apt install python3-wstool 创建ROS工程 $ mkdir -p ~/UAV/src $ cd ~/UAV/src $ catkin_init_workspace # initialize your catkin workspace $ wstool init 下载源码 git clone git@github.com:ethz-asl/rotors_simulator.git 源码链接: https://github.com/eth

漫长IT路 5863

解决TextMeshPro在AB打包中的字体冗余问题:源码修改全记录

本文详细介绍了如何解决TextMeshPro在AB打包中的字体冗余问题,通过源码改造和工程实践优化Unity项目的性能。内容包括资源加载路径重构、AB打包策略优化及运行时加载方案,有效减少包体体积和构建时间,提升内存效率。

weixin_42558257的博客 185

getCurrentSession与openSession的区别

getCurrentSession与openSession的区别 一:getCurrentSession () 使用当前的 session 注意:1,使用 SessionFactory.getCurrentSession() 需要在 hibernate.cfg.xml 中如下配置: 如果采用 jdbc 独立引用程序配置如下: thread 如果采用了 JTA 事务配置如下 jta 2,使用的是 getCurrentSession 来创建 session 的话,在 commit 后,session 就自动被

weixin_46161383的博客 208

EDA工具安装第一步:Synopsys Installer的配置与图形化界面使用详解

本文详细解析了EDA工具安装的关键第一步——Synopsys Installer的配置与使用。文章阐述了其作为统一部署管理器和依赖协调者的核心作用,并分步详解了如何通过图形化界面高效安装EDA工具,同时介绍了命令行批处理等进阶技巧,旨在帮助工程师快速搭建稳定的芯片设计环境。

zeta9的博客 342

getCurrentSession()时报错,no session found for current thread,解决方案

当我们使用spring框架,通过getCurrentSession()获得与线程绑定的session时,可能会遇到no session found for current thread的错误,要解决该错误,我们必须先知道该错误产生的原因是什么。 无论我们是在用Hibernate4 与 spring3集成还是其他的什么情况,该错误产生的根本原因就是当我们在调用getCurrentSession

YQFCXY的博客 1万+

别再只改config了!YOLO/RT-DETR多通道输入实战:数据集结构、多卡训练与参数优先级避坑指南

本文详细解析了YOLO/RT-DETR模型在多通道输入(如8通道多光谱图像)中的实战应用,涵盖数据集结构优化、数据加载器改造、模型参数调优及多卡训练配置。针对常见的多通道输入报错问题,提供了系统的解决方案和性能优化技巧,帮助开发者高效实现非标准数据格式的适配与训练。

weixin_30955617的博客 397

发那科机器人karel程序

备份和查看发那科机器人中的 Karel 程序的过程主要包括从示教器中备份程序,并通过 RoboGuide 等仿真软件查看和运行程序。步骤相对简单,但需要确保你的设备和软件已经设置好,可以通过 FTP 或直接从示教器的外部存储设备进行操作。如果你在操作过程中遇到问题,建议查阅相关的用户手册或联系发那科的技术支持,确保设备设置正确。如果你有更具体的问题或需要进一步帮助,欢迎继续提问!希望如上措施及解决方案能够帮到有需要的你。

**My Coding Family** 1602

SSH中使用getCurrentSession()获得session

SSH中使用getCurrentSession()获得session 在hibernate的配置文件中增加属性:thread如下表红色部分    root       jdbc:mysql://localhost:3306/dbtest          org.hibernate.dialect.MySQLDialect

生命从来就不是水晶的阶梯 7887

高德地图API如何使用

通过以上步骤,您可以成功接入并使用高德地图API来为您的应用添加丰富的地图功能。

QQ_778132974的博客 4786

用ssh整合时,用sessionfactory的getCurrentSession()获取不到session

在用ssh整合时,一开始用的是getCurrentSession(),获取当前线程上的session,但是总是抛异常,不能获取。 后来用sessionfactory的openSession(),但是,会发现一旦程序多次运行就会报错,提示没得session可获取。 那么怎么解决呢。 在beans.xml里面的hibernateProperties配置hibernate.current_sess...

weixin_30765505的博客 287

大数据领域数据产品的交通运输行业应用

您是否经历过早高峰被堵在桥上,看着导航显示“前方5公里缓行”却无能为力?是否见过货车司机绕远路导致成本飙升?这些“交通痛点”的背后,是传统交通管理依赖经验决策的局限。本文将聚焦“大数据数据产品”这一核心工具,从技术原理到实际应用,全面解析它如何为交通运输行业“开天眼”,解决从城市拥堵到物流效率的一系列难题。本文将按照“问题引入→概念拆解→技术原理→实战案例→应用场景→未来趋势”的逻辑展开,用生活化比喻降低理解门槛,用代码和数学模型提升专业性,最终帮您建立“大数据+交通”的完整认知框架。交通数据。

操作系统内核探秘的博客 237

AUTOSAR-WdgM篇

Wdg通常有两种:一种是芯片内部自带的片内看门狗,另一种是在芯片外部通过SPI这种接口连接的片外看门狗。MCAL只负责常用的有MCU内部看门狗,片内看门狗的特点是Wdg模块是直接访问相关硬件寄存器。内部看门狗依赖于系统时钟片外看门狗属于设备抽象层负责,通常需要使用MCAL提供的其他模块(比如SPI,DIO,PWM等)来访问/控制外扩看门狗芯片。这种不能直接访问硬件寄存器。Wdg Driver:有三种模式slow mode,fast mode ,off mode。

qq_329563867的博客 5830

Hibernate getCurrentSession()与openSession()的区别

在使用ssh框架开发时,使用spring代替管理数据库的连接,一般的dao层格式为 先获取session,然后开事务,然后处理逻辑,然后关闭事务。 在开发中遇到一个问题。在dao层处逻辑时,需要跳到其他的层去处理逻辑,那么如果在这个其他逻辑的地方也是用了同样的方式 获取session,并且提交事务后,返回原逻辑中使用该session会报session is close的异常。 原因:查...

Stepeh的博客 485

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

openSession与getCurrentSession

在比较openSession和getCurrentSession这两个方法之前,我们先认识一下这两个方法。在进行配置信息管理时,我们一般进行一下简单步骤:Configuration cfg = new Configuration(); // 获得配置信息对象 SessionFactory sf = cfg.configure().buildSessionFactory(); //解析并建立Sessi

Aluo 889

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

Hibernate中解决No Hibernate Session bound to thread问题

引用:忘了 首先是getCurrentSession()与openSession()的区别: 1、getCurrentSession()与openSession()的区别?   * 采用getCurrentSession()创建的session会绑定到当前线程中,而采用openSession()创建的session则不会   * 采用getCurrentSession()...

a453202743的博客 638

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

[故障及解决]使用spring集成的ssh,报错No Session found for current thread

Spring框架的web工程中,使用quartz机制,在实现类中访问数据库时,会出现No Session found for current thread错误。 出错代码 getCurrentSession()方法。 HibernateTemplate().getSessionFactory().getCurrentSession()

qiantudou的专栏 1906

hibernate的session的产生方式,区别在哪里?

hibernate的session的产生方式,区别在哪里?如何产生? session的产生方式有哪些,并且为什么要分这个? 产生流程: 1、方式一 sessionFactory.opensession():一般的crud操作我们用的是这个操作,只有增删改才用到事务,查询不需要。 // session的第一种产生方式:opensession():每一次都产生一个新对象 @

Mr_li13的博客 1066
上一篇: openSession、getCurrentSession区别
下一篇: JAVA笔试之打印昨天的当前时刻
Software_King
博客等级 码龄14年 4粉丝 47原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值