dao

Spring + Hibernate : a different object with the same identifier value was already associated with the session

六月ゝ 毕业季﹏ 提交于 2019-11-26 17:49:52
In my application, which uses Spring and Hibernate, I parse a CSV file and populate the db by calling handleRow() every time a record is read from the CSV file. My domain model: 'Family' has many 'SubFamily' 'SubFamily' has many 'Locus' a 'Locus' belongs to a 'Species' Family <-> SubFamily <-> Locus are all bi-directional mappings. Code: public void handleRow(Family dummyFamily, SubFamily dummySubFamily, Locus dummyLocus) { //Service method which access DAO layers CommonService serv = ctx.getCommonService(); boolean newFamily=false; Family family=serv.getFamilyByFamilyId(dummyFamily

Where should “@Transactional” be place Service Layer or DAO

你离开我真会死。 提交于 2019-11-26 17:26:36
问题 Firstly it is possible that I am asking something that has been asked and answered before but I could not get a search result back . Okay generally (or always so far:) ) We define transactional annotations on service layer typical spring hibernate crud is usually Controller->Manager->Dao->Orm . I now have a situation where I need to choose between the domain model based on client site . Say client A is using my domain model all is good but then an other client site would give me a web service

JDBC(工具类,CRUD,Dao模式、PrepareStatement)

本小妞迷上赌 提交于 2019-11-26 17:19:15
JDBC JAVA Database Connectivity java数据库连接 说白了:JDBC就是sun公司提供的一种数据库访问规则、规范。由于数据库种类较多,并且java语言使用比较广泛,sun公司就提供了一种规范,让其他的数据库提供商去实现底层的访问规则。 我们的java程序只要使用sun公司提供的jdbc驱动即可。 使用JDBC的基本步骤 导入驱动 java项目文件(就是自己创建的peoject)右击 -> Build Path -> Configure Build Path -> Libraries ->Add External JARS -> 选择自己已经下载的 mysql-connector-java-8.0.16.jar(本人下载的是8.0.16版本) 注册驱动 DriverManager.registerDriver(new com.mysql.jdbc.Driver()); 建立连接 Connection conn = null; conn = DriverManager.getConnection("jdbc:mysql://localhost/javatest?serverTimezone=UTC", "用户名", "密码"); 创建Statement Statement st = null; st = conn.createStatement();

AOP的理解

拈花ヽ惹草 提交于 2019-11-26 17:16:10
描述:对于AOP术语一些总结以及相关的案例 标签:Spring 面向切面编程 目录 {:toc} 几个术语的基本解释 通知 直接明白的说就是你想要的功能(为了更清晰的逻辑,让你的业务逻辑去关注本身的业务,而不是去想其他的事情,这些其他的事情包括,比如安全、事务、日志等) 连接点 就是允许你使用通知的地方,比如每个方法的前后或者抛出异常时都是连接点。Spring只支持方法连接点 切入点 比如说,你的一个类里有15个方法,那不就是几十个连接点了,但是你不可能在所有方法上面都写一个通知吧,你只是想让其中几个方法,就可以使用 切点去筛选连接点 ,选中那几个你想要的方法 切面 切面就是通知和切入点的集合,也就是一个类。没连接点什么事情,连接点就是为了让你更好的去理解切点。通知说明了干什么和什么时候干(通过@Before @After等注解就可以明白),而切入点说明了在哪里干(指定到底是哪个方法) 引入 允许我们向现有的类(目标类)添加新方法属性。其实说白了就是切面类(这里不就是定义了切入点 通知嘛),就是切面类可以为目标类添加新方法属性。 目标 也就是上面提到的目标类,也就是需要被通知的对象。这个目标类的话就是我们的真正业务逻辑,而不是其他事情(其他事情在切面类中去做,上面提到的日志、事务等) 代理 怎么实现整套AOP机制的,都是通过代理 织入

Hibernate: CRUD Generic DAO

巧了我就是萌 提交于 2019-11-26 15:15:00
问题 My web application has got a lot of service tables/entities, such as payment_methods , tax_codes , province_codes , etc. Each time I add a new entity, I have to write a DAO. The thing is that, basically, they are all the same, but the only difference is the entity class itself . I know that Hibernate tools can generate the code for me automatically but I can't use them now (don't ask why) so I'm thinking of a Generic DAO . There's a lot of literature about that but I can't put pieces together

DAO and Service layers (JPA/Hibernate + Spring) [duplicate]

假如想象 提交于 2019-11-26 15:01:26
问题 This question already has an answer here: Java EE Architecture - Are DAO's still recommended when using an ORM like JPA 2? 2 answers I'm designing a new app based on JPA/Hibernate, Spring and Wicket. The distinction between the DAO and Service layers isn't that clear to me though. According to Wikipedia, DAO is an object that provides an abstract interface to some type of database or persistence mechanism, providing some specific operations without exposing details of the database. I was

Access - compare two tables and update or insert data in first table

你。 提交于 2019-11-26 14:49:04
问题 In my Access datebase I have a two tables: Table1: PersNum Name Surname 2321 Lenora Springer 2320 Donya Gugino 3326 Leland Wittmer 4588 Elmer Mcdill Table2: PersNum Name Surname 2321 Lenora Farney 2320 Donya Willimas 3326 Leland Wittmer 4588 Maya Mcdill 7785 Yolanda Southall 1477 Hailey Pinner I need to find a way to check the personal number (field "PersNum"), and then if PersNum exist, update Name and Surname in Table1. If PersNum doesn't exist, insert new row in Table1. Expected results:

SpringBoot秒杀系统(一)Dao 层

半腔热情 提交于 2019-11-26 14:27:14
SpringBoot秒杀体统(一)Dao 层 学习自慕课网( https://www.imooc.com/u/2145618/courses?sort=publish ),原项目为SSM,现改造为springboot项目。 秒杀系统业务流程 1、问题在于如何不超卖、使用户如何不超买。 可能出现的问题: 难点分析: 使用事务+ 行级锁来约束购买 事务: 数据库 管理系统执行过程中的一个逻辑单位,由一个有限的 数据库 操作序列构成。 通过开始事务、更新库存数量、插入购买记录、提交 来完成对一个用户的秒杀商品过程。 行级锁: 当一个用户完成购买之后,下一个用户才能继续使用这条秒杀商品记录。 秒杀功能实现 整体项目分类一览 Dao层编写 Dao层,也就是数据层,在ssm的项目中常用dao 这个包来存放相关数据,在springboot项目中,使用mapper来进行数据的交互。 关于如何 创建一个springboot+mybatis 项目,可以查看这个: Spring Boot + Mybatis+druid 整合 1、数据库编写 seckill 表 用来记录 需要秒杀的商品 sucess_killed 表 用来记录成功秒杀的记录 SQL 语句 DROP TABLE IF EXISTS ` seckill ` ; CREATE TABLE ` seckill ` ( ` seckill_id

SSM框架原理,作用及使用方法

只谈情不闲聊 提交于 2019-11-26 13:59:45
作用: SSM框架是spring MVC ,spring和mybatis框架的整合,是标准的MVC模式,将整个系统划分为表现层,controller层,service层,DAO层四层 使用spring MVC负责请求的转发和视图管理 spring实现业务对象管理,mybatis作为数据对象的持久化引擎 原理: SpringMVC: 1.客户端发送请求到DispacherServlet(分发器) 2.由DispacherServlet控制器查询HanderMapping,找到处理请求的Controller 3.Controller调用业务逻辑处理后,返回ModelAndView 4.DispacherSerclet查询视图解析器,找到ModelAndView指定的视图 5.视图负责将结果显示到客户端 Spring:我们平时开发接触最多的估计就是IOC容器,它可以装载bean(也就是我们Java中的类,当然也包括service dao里面的),有了这个机制,我们就不用在每次使用这个类的时候为它初始化,很少看到关键字new。另外spring的aop,事务管理等等都是我们经常用到的。 Mybatis:mybatis是对jdbc的封装,它让数据库底层操作变的透明。mybatis的操作都是围绕一个sqlSessionFactory实例展开的

(二)MVC项目+c3p0连接池

拜拜、爱过 提交于 2019-11-26 12:11:15
一.项目架构 注:删除了原有的数据库工具,添加了c3p0数据库工具类,添加了c3p0的配置文件,修改了Dao类以及servlet类 二.修改或添加的类 1.C3p0Helper(暂时不了解事务回滚之类的怎么用或者有什么用,只用了连接和关闭) package helper; import java.sql.Connection; import java.sql.SQLException; import javax.sql.DataSource; import com.mchange.v2.c3p0.ComboPooledDataSource; public class C3p0Helper { private static String configName = "mysql"; //如果无参,则使用c3p0-config.xml中的default-config,该处使用mysql的配置 private static DataSource ds = new ComboPooledDataSource(configName); /** * 它为null表示没有事务 * 它不为null表示有事务 * 当开启事务时,需要给它赋值 * 当结束事务时,需要给它赋值为null * 并且在开启事务时,让dao的多个方法共享这个Connection */ private static