dao

Why are the transactions rolled back even when propagation=Propagation.REQUIRES_NEW in second method in Spring service class?

吃可爱长大的小学妹 提交于 2019-12-06 02:26:07
问题 Basic settings are all fine now and I started to try transactions. Struts+Spring+Hibernate annotation transaction manager. This is the sample code in Action, will call a service class: userService.addUser(); Here is the addUser() method in service class: @Transactional(value="deu" ) public void addUser() { userDao.addUser(); this.addUser2(); } First, I called addUser in userDao, which will insert a user. Second, I called addUser2 in another method in this service class. @Transactional(value=

dao

帅比萌擦擦* 提交于 2019-12-06 02:06:49
package com.gzsxt.dao.impl; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import javax.jws.soap.SOAPBinding.Use; import com.gzsxt.dao.SysUserDao; import com.gzsxt.pojo.SysUser; import com.gzsxt.util.BaseUtil; public class SysUserDaoImpl implements SysUserDao{ //实例化工具类 BaseUtil util=new BaseUtil(); @Override public SysUser userLogin(String username, String password) { SysUser user=null; //编写SQL语句 String sql ="select * from s_user where s_userName=? and s_password=?"; PreparedStatement statement=util

ssm架构数据库连接字符串配置到外部报错

折月煮酒 提交于 2019-12-06 01:56:19
报错: Could not load driverClass ${jdbc.driver} 解决办法: 将 <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <!-- 注入sqlSessionFactory --> <property name="sqlSessionFactory" ref="sqlSessionFactory"/> <!-- 给出需要扫描Dao接口包 --> <property name="basePackage" value="com.eggtwo.euq.dao"/> </bean> 改为: <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <!-- 注入sqlSessionFactory --> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/> <!-- 给出需要扫描Dao接口包 --> <property name="basePackage" value="com.eggtwo.euq.dao"/> </bean> 来源: https://www.cnblogs.com/eggTwo/p/11955754

Java Generic of Another generic

孤者浪人 提交于 2019-12-05 22:54:39
问题 I have interface: interface Identifable<T extends Serializable> { T getID(); } and class that implement this: public class Cat implements Identifable<Long> { public Long getID(){...}; } everything works fine. so far. Now I want to create GenericDAO, why I cannot create this?: public abstract GenericDAO<T extends Identifable<S>> { T getByID(S id); } I can only declare my GenericDAO as this: public abstract GenericDAO<T extends Identifable, S> { T getById(S id); } And complete class: public

Dao设计模式简单实现

最后都变了- 提交于 2019-12-05 19:23:13
一、什么是Dao设计模式   Dao设计模式封装了操作具体数据库的细节,对业务层提供操作数据库的接口,因此降低了业务层代码与具体数据库之间的耦合,有利于人员分工,增加了程序的可移植性。   Dao设计模式中主要包含这5个模块:     1、VO类:VO(Value Object)即值对象,每一个值对象对应一张数据库表,便于我们传递数据。     2、Dao接口:Dao接口定义了操作数据库的方法,业务层通过调用这些方法来操作数据库。     3、Dao实现类:操作数据库的方法的具体实现,封装了操作数据库的细节。     4、Dao工厂类:用于代替new操作,进一步降低业务层与数据层之间的耦合。     5、数据库连接类:封装了连接数据库、关闭数据库等常用的操作,减少重复编码。   下面我们应用Dao设计模式来实现一个简单的转账操作,加深对其的理解。 二、Dao设计模式实现   首先,我们创建vo、dao、factory、util包来分别存放Dao设计模式5个模块的代码。因为我们使用的是JDBC连接MySQL数据库,所以还需要创建一个lib包存放并引用JDBC驱动。除此之外,我们还需要创建一个test包进行代码的测试。创建好后的目录结构如下:   接着设计一张user表,表中包含了用户基本信息和余额,并插入一些数据。   根据user表在vo包中创建VO类user.java。 1

Spring/Spring-Boot 学习 paoding-rose-jade 连接MySQL数据库

↘锁芯ラ 提交于 2019-12-05 17:38:25
新建一个 spring-boot 工程, maven 的 pom 文件中添加如下依赖: <!--spring-boot起步依赖--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <!--lombok依赖,可简化代码--> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency> <!--paoding-rose-jade基础依赖, 注意去除paoding-rose-jade中的spring相关依赖,否则会与项目本身的spring-boot冲突引发无法实例化bean的错误--> <dependency> <groupId>com.54chen</groupId> <artifactId>paoding-rose-jade</artifactId> <version>1.1</version> <!--排除paoding-rose-jade中的Spring相关依赖--> <exclusions> <exclusion>

Error testing DAOs: sun.reflect.generics.reflectiveObjects.TypeVariableImpl cannot be cast to java.lang.Class

雨燕双飞 提交于 2019-12-05 17:29:52
I am very new to Spring + Hibernate, and I am running tests to see if my DAOs are working. I get the following error which upon searching in Google yields a lot of different answers (mostly of typos, which I have checked). I'm hoping you can help me out on this: java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:308) at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109) at org.springframework

(二)MVC项目+c3p0连接池

♀尐吖头ヾ 提交于 2019-12-05 16:49:02
一.项目架构 注:删除了原有的数据库工具,添加了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

Access as a front-end to SQL Server - ADO vs DAO?

若如初见. 提交于 2019-12-05 16:06:11
I have a project that will be using Access 2003 as the front-end and the data will be stored in SQL Server. Access will connect to SQL Server via linked tables with all the database logic (stored procedures, views) within SQL Server. Given this setup, would it be better to use ADO or DAO within Access? Is it just a matter of preference or is one more suited to Access as a front-end and SQL Server as the data store? Especially when using linked tables. Thanks. Write pass-thru queries as opposed to the linked table approach. Performance will be greatly improved. Writing an Access app? Create

SSM框架随笔

删除回忆录丶 提交于 2019-12-05 09:48:21
SSM框架 1. MVC各层级间的作用及关系 1.1 表现层(springMVC) Controller层(Handler层) 负责具体的 业务模块流程的控制 。 Controller层通过要 调用Service层的接口 来控制业务流程,控制的配置也在Spring配置文件里面。 1.2 业务层(Spring) Service层 负责 业务模块的逻辑应用设计 。 首先设计其接口,然后再实现他的实现类。通过对Spring配置文件中配置其实现的关联,完成此步工作,我们 就可以通过调用Service的接口来进行业务处理。最后通过调用DAO层已定义的接口,去实现Service具体的实现类。 1.3 持久层(Mybatis) Dao层(Mapper层) 负责 与数据库进行交互设计 ,用来 处理数据的持久化工作 。 DAO层的设计首先是设计DAO的接口,然后在Spring的配置文件中定义此接口的实现类,就可在其他模块中调用此接口来进行数据业务的处理,而不用关心接口的具体实现类是哪个类,这里用到的就是反射机制,DAO层的数据源配置,以及有关数据库连接的参数都在Spring的配置文件中进行配置。 1.4 视图层:View层 负责前台jsp页面的 展示 。 此层需要与Controller层结合起来开发。 1.5 各层间的联系: ​ 本来Controller层与View层是可以放在