spring整合hibernate配置注解事务的相关问题

Spring 利用MyEclipse整合spring与Hibernate ssh:所有的Struts以及hibernate的控制都交由Spring负责了,而且Spring利用自身的IOC&AOP的特性,可以让这些组件整合之后变得操作更加容易。 本次使用myeclipse进行开发框架的整合,之所以使用此类整合操作,目的是:MyEclipse提供的开发包是全面的; 如果要整合需要分为两个操作部分; 首先进行Spring+Hibernate的整合; 在位项目添加Str... 阅读详情

<bean id="sessionFactory"  
			class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"  
			lazy-init="false">  
			<property name="dataSource">
			<ref bean="dataSource" />
			</property>  
			<property name="mappingResources">  
			<list>  
			<value>com/aaa/healthHouse/model/Cusnation.hbm.xml</value>
			</list>  
			</property>  
			<property name="hibernateProperties">  
			<props>  
			<prop key="hibernate.dialect">  
			org.hibernate.dialect.MySQLDialect
			</prop>  
			<prop key="hibernate.hbm2ddl.auto">update</prop>  
			<prop key="hibernate.show_sql">true</prop>
			<!--<prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate3.SpringSessionContext</prop>  
			--></props>  
			</property>  
			</bean>  

这一段中,hibernate.current_session_context_class这一项不需要配置,当程序出现No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here这个错误时,可能是因为<tx:annotation-driven transaction-manager="txManager" proxy-target-class="false"/>这段配置中的proxy-target-class中的值为true,即表示代理接口是指定的class,而不是接口代理,当我们在dao层的接口进行@Transaction注解时,会出现这个错误。

当我们将hibernate.current_session_context_class这一项的配置的值设为thread时,即使注解@Trsansaction注解到了接口并且指定代理在类,也能获得session,但是此时获得的session会出现  not actived transaction 即,当前上下文不存在活跃的事务,其实此时可能session不存于spring的管理中,解决的办法:

1、将<tx:annotation-driven transaction-manager="txManager" proxy-target-class="false"/>中的proxy-target-class设为false,,默认就使用接口代理,即默认值即为false

2、@Transaction注解写在dao的实现类层,但是这样违背了我们面向接口编程的思想,不推荐

Java高手速成 | Spring、JPA与Hibernate的整合 Spring、JPA与Hibernate的整合 阅读详情

相关推荐

spring mvc+hibernate 实现事务管理(全注解版)

spring mvc hibernate 实现事务管理 jar包管理用maven,启动服务器用jetty,里边还有memcached数据库,但是本例子没有用到。

spring 注解 事务,声明事务共存的情况下,先后顺序

首先先看配置文件: <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> update true true true true true org.hibernate.diale

feng27156的专栏 1万+

从信号到振镜:STM32F103 + XY2-100协议 + AM26LS31芯片的激光打标/雕刻系统信号链搭建指南

本文详细介绍了基于STM32F103微控制器和XY2-100协议的激光打标/雕刻系统信号链搭建方法。从数字振镜控制协议解析、AM26LS31差分驱动电路设计到信号完整性优化,提供了一套完整的解决方案,帮助工程师实现高精度激光控制系统的开发与调试。

weixin_42536058的博客 237

Spring3与hibernate4集中式声明事务管理与注解式事务管理

Email:137268431@qq.com Blog:http://blog.youkuaiyun.com/LzwGlory 概述: 还像往常一样先了解下基础知识: Hibernate是一个开源的ORM框架,能自动为对象生成相应SQL并透明的持久化对象到数据库,我们首先来了解一下什么是“ORM”。 ORM全称对象关系映射(Object/Relation Mappi...

LzwGlory的专栏 293

python采集keep运动数据

我国2009年确立“全民健身日”;2012年,“广泛开展全民健身运动”写入十八大报告;到2014年上升为国家战略,全民健身的分量越来越重。推动全民健身和全民健康深度融合,通过全民健身实现全民健康。 全民健身运动在我国越来越普及,每天清晨和傍晚时分,城市的广场上、公园里,到处是运动健身的人们,跑步、打球、跳舞、游泳、打太极拳等运动项目十分丰富,人们在运动中获得越来越多的幸福感。 随之诞生出了很多运动app,例如keep,咪咕,微信等,大家可以通过app随时记录自己的运动数据,特别是对于很多的减肥人群来说,通过

Z_suger7的博客 5658

【论文阅读】2021-(Pidinet)Pixel Difference Networks for Efficient Edge Detection

文章目录摘要1. Introduction 摘要 motivations: 基于CNN的边缘检测的高性能是通过一个大的预训练CNN主干来实现的,该主干占用大量内存和能量。传统边缘检测器(如Canny、Sobel和LBP)很少被研究。 contributions: 提出了一种简单、轻量级但有效的架构,称为像素差分网络(PiDiNet),用于有效的边缘检测。PiDiNet采用了新颖的像素差卷积,将传统的边缘检测算子集成到现代CNN中流行的卷积运算中,以增强任务性能。 experiments: 在BSDS500

轻舟的万重重山 1万+

spring整合hibernate事务管理的四种方式,以及事务的传播行为和隔离级别介绍

转自:http://blog.youkuaiyun.com/jianxin1009/article/details/9202907    为了保证数据的一致性,在编程的时候往往需要引入事务这个概念。事务有4个特性:原子性、一致性、隔离性、持久性。          事务的种类有两种:编程式事务和声明式事务。编程式事务就是将事务处理放在程序中,而声明式事务则是通过配置文件或者注解进行操作

zhangqindabendan的博客 1万+

Windows非分页缓冲池内存泄漏实战:PoolMon与RAMMap高效排查指南

本文详细介绍了Windows系统中非分页缓冲池内存泄漏的实战排查方法。当系统出现卡顿且内存占用异常增长时,通过RAMMap工具快速定位非分页缓冲池异常,并利用PoolMon监控内核内存分配标签,精准锁定泄漏源。文章提供了从确认症状、安装工具到使用findstr命令溯源驱动文件的完整五步排查流程,并总结了常见泄漏标签与解决方案,帮助用户高效解决深层系统内存问题。

weixin_28455801的博客 1012

最最最详细SSH框架整合技术

Spring 与 Hibernate 整合 除了 JdbcTemplate 外,Spring 还可通过 Hibernate 来完成 Dao 的工作。即将 Spring 与Hibernate 进行整合。 举例:项目 spring_hibernate(在 dao_jdbcTemplate 基础上修改) 1、导入 Jar 包 除了 Spring 的基本 Jar 包外,还需要以下几种 Jar 包: (1)Spring AOP 的两个 Jar 包 (2)AspectJ 的两个 Jar 包 (3)Spring

dagasad的博客 352

ransac拟合2D圆(三点定圆 c++详细版)

RANSAC(Random Sample Consensus,随机采样一致性)算法是一种基于随机采样的迭代算法,主要用于从一组包含大量噪声和异常值(外点)的数据中估计数学模型的参数。

twnkie的博客 1047

996引擎 - 读写变量性能测试

单轮100万次读写,取3轮平均耗时(毫秒),有效读取率均为100%,数值越小性能越优。

灵台方寸山斜月三星洞 245

简化版电子支付项目问题总结

1.spring3.2中 @component注解要引入spring-context-...jar包   2.由于在spring中配置事务,要用到org.apache.commons.dbcp.BasicDataSource这个类,因此你还要下载apache的commons-dbcp-1.4.jar 以及这个dbcp包依赖的commons-pool-1.6.jar包   3.hiber...

wtz1234567的博客 280

GEE土地分类:基于sentinel-2的ResNet深度学习模型的土地分类

本文提出了一种基于深度学习的土地覆盖分类方法,通过集成Google Earth Engine和PyTorch框架实现自动化监测系统。技术方案包括:1) 使用Sentinel-2和Landsat-8卫星影像作为数据源,结合EuroSAT标准数据集;2) 采用ResNet50和U-Net构建深度学习模型;3) 建立端到端处理流程,包含数据预处理、模型训练和评估体系。实验结果表明,该方法在EuroSAT数据集上达到90%的分类准确率,成功应用于农作物监测、城市扩张分析等场景。系统配置基于Python 3.8+环境

此星光明博客 372

spring4+hibernate5整合

hibernate在实际应用中,很少单独使用的,基本都是和spring一起使用,这里介绍如何整合spring4+hibernate5。hibernate与spring整合,配置文件hibernate.cfg.xml就不需要了,配置信息直接提到spring配置文件里面,hibernate的sessionFactory交给spring容器管理,不再单独通过Configuration来构建。 整合首先...

feinifi的博客 3065

SolidWorks_模具设计5_分型线生成

分型线是模具设计的核心要素,直接影响产品质量、脱模可行性和制造成本。本文系统介绍了分型线生成技术,包括三种核心算法:基于凸包的方法适用于简单几何,可见性分析处理复杂曲面,曲率特征优化则能找到自然分界。文章提供了完整的Python实现示例,涵盖点云投影、网格处理和分型线评估等关键技术。通过理解这些原理和方法,工程师可以更高效地设计出满足外观要求、易于加工的分型线方案,显著提升模具设计质量和效率。

H17853509096的博客 179

深度学习工具包 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")

Spring全家桶之SpringData——Spring 整合Hibernate与Hibernate Jpa

Spring 整合Hibernate与Hibernate Jpa 一. Spring 整合HibernateHibernate简单环境搭建Hibernate介绍搭建步骤1. 相关jar的的导入2 .编写配置文件完成框架的整合(src下)通过hibernate完成crud操作0. 创建数据库1. 创建实体 ,加注解2 .配置HibernateTemplate对象3. 编写user Dao接口与接...

时间静止 1万+

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

[Hibernate]spring与Hibernate整合配置文件

Hibernate框架与spring整合相关配置: 文件名:applicationContext.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSc...

朱同学的博客 865

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

[Hibernate JPA]spring与Hibernate JPA整合配置文件

Hibernate框架与spring整合相关配置: 文件名:applicationContext.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSc...

朱同学的博客 379

1.hibernate与spring的整合与mybatis与spring的整合大致区别

1.hibernate与spring的整合与mybatis与spring的整合大致区别 hibernate与spring的整合过程: 1、导入hibernate、spring的pom依赖 2、spring-hibernate.xml 数据库信息文件的注册 数据库连接池C3P0的配置 sessionfactory工厂相关信息的配置(hibernate.cfg.xml) 数据源 数据方言 show_s...

qq_43195035的博客 319

Spring整合Hibernate

1 概述 Spring支持大多数流行的ORM框架,包括Hibernate、JDO、TopLink、Mybatis和JPA。 Spring对这些ORM框架的支持是一致的,因此可以把和Hibernate整合技术应用到其他ORM框架上. Spring 2.0同时支持Hibernate 2.x和3.x。但Spring 2.5只支持Hibernate 3.1或更高版本。 对于Hibernate而言,必须从原生的Hibernate API中构建SessionFactory。 此外,应用程序也无法利用Sprin

naumy的博客 779

Activiti5工作流框架学习之Struts2+Hibernate+Spring整合配置

测试环境WindowsSTSMysql5Jdk1.8Tomcat8 Maven3Struts2 + Spring4 + Hibernate3 + Activiti5.17一、整合Spring与Hibernate3配置DataSourceapplication-config.xml内容:<!-- 加载数据库配置文件 --> <context:property-placeholder location=

一大三千的博客 4931

Spring + Hibernate整合(无hibernate.cfg.xml,无映射文件)

依据前一篇《Spring + Hibernate整合》:https://blog.youkuaiyun.com/wenwenliuyunabcd/article/details/100703434,进行修改 spring容器配置beans.xml: 此处同时做了下事务的注解驱动 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http...

wenwenliuyunabcd的博客 757

springMVC整合hibernate的时候数据插入需要flush问题

hibernate中openSession和getCurrentSessionopenSession需要手动的管理事务,每次打开一个新的session getCurrentSession在当前线程中找一个session,如果没有则新建一个。不需要手动close,但是需要定义事务管理spring配合hibernate使用getCurrentSession由于使用getCurrentSession需要

fun 1644

Hibernate【与Spring整合】

前言 前面已经学习了如何使用Spring与Struts2进行整合,本博文主要讲解如何使用Spring对Hibernate进行整合 Spring和Hibernate整合的关键点: SessionFactory对象交给Spring来创建 Hibernate的事务交给Spring进行管理 Spring和Hibernate整合步骤 引入jar包 连接池/数据库驱动包 Hibernate相...

awxj68104的博客 70

Spring与Hibernate 整合 xml配置

* Spring 整合 Hibernate 整合什么?     1.由 Spring IOC容器来管理  Hibernate 的 SessionFactory     2.让 Hibernate 使用上 Spring 的声明式事务 * 整合步骤: 1. 加入 Hibernate   1.jar包   2.添加hibernate配置文件:hibernate.cfg.xml  

世事如棋__2016的博客 418
上一篇: jdbc连接oracle10g测试数据库插入
下一篇: 使用createSQLQuery直接封装成自定义对象
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值