- 浏览: 187963 次
- 性别:
- 来自: 成都
-
最新评论
-
ls_autoction:
非常谢谢!:oops:
webservice注解 -
ganbo:
helloword
hibernate之openSession和getCurrentSession -
ganbo:
...
hibernate之openSession和getCurrentSession -
zizhengwang:
文章介绍的很全面,帮助我解决了问题,谢谢
hibernate之级联cascade和关系维持inverse -
yccn1984:
/** * 子类进行注入 * ...
DAO和Service公共抽象接口实现
文章列表
ArrayList对比Vector
- 博客分类:
- java基础
主要区别就是ArrayList是非线程同步的,而Vector是线程同步的
AyyayList的构造函数有三个:
public ArrayList()
构造一个初始容量为 10 的空列表
public ArrayList(Collection<? extends E> c)
构造一个包含指定 collection 的元素的列表,这些元素是按照该 collection 的迭代器返回它们的顺序排列的。
public ArrayList(int initialCapacity)
构造一个具有指定初始容量的空列表。
Vector:
...
首先研究下Collection下的同步和非同步,例如ArrayList
List 接口的大小可变数组的实现。实现了所有可选列表操作,并允许包括 null 在内的所有元素。除了实现
List 接口外,此类还提供一些方法来操作内部用来存储列表的数组 ...
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="${jdbc.driver}"></property>
<property name="jdbcUrl" value="${jdbc.url} ...
从上篇文章分析得出,hibernate初始化时,flushBeforeCompletion、autoCloseSession默认为false
releaseMode为auto。还有hibernate.jdbc.batch_size默认为0等。那现在来分析openSession和getCurrentSession的区别就不难了。
首先进入sessionFactory的实现类SessionFactoryImpl,接到上篇文章继续分析:
上篇文章的configuration最后调用代码如下:
return new SessionFactoryImpl(
this,
...
hibernate通过sessionFactory有两种方式获取session:一种是openSession,一种是getCurrentSession
简单区别
1、openSession创建session时autoCloseSessionEnabled参数为false,即在事物结束后不会自动关闭session,需要手动关闭,如果不关闭将导致session关联的数据库连接无法释放,最后资源耗尽而使程序当掉。 2、getCurrentSession创建session时autoCloseSessionEnabled,flushBeforeCompletionE ...
一个老师有多个学生,同样一个学生有多个老师,配置如下:
@ManyToMany(fetch=FetchType.LAZY,cascade={CascadeType.PERSIST,CascadeType.MERGE})
@JoinTable(name = "teacher_student", joinColumns = @JoinColumn(name = "teacher_id"), inverseJoinColumns = @JoinColumn(name = "student_id"))
@OrderBy(" ...
hibernate一对多,多对一双向关联
假设一个老师对应多门课程,一门课程只对应一个老师
@OneToMany(mappedBy="teacher",fetch=FetchType.LAZY,cascade={CascadeType.MERGE,CascadeType.REMOVE})
private Set<Course> courses = new HashSet<Course>();
@ManyToOne(cascade={CascadeType.MERGE})
@JoinColumn(name = "tea ...
这里使用学生和学生的详细信息表来表述,OneToOne有三种配置
1、主键关联
主键关联是最复杂也是最常用的关联方式。
配置如下:studentInfo主键生成策略,使用当前对象中student属性的主键来作为本对象的主键
@Id
@GeneratedValue(generator="pkGenerator")
@GenericGenerator(name = "pkGenerator", strategy = "foreign", parameters = @Parameter(name = &q ...
hibernate的关联关系,重点在理解级联cascade和inverse
1、cascade一般用在级联保存,级联更新,级联删除上
1.1cascade注解有两种,一种是基于hibernate注解
org.hibernate.annotations.Cascade
org.hibernate.annotations.CascadeType
支持一下级联
ALL,
PERSIST//级联持久化,调用session.persist()时会触发级联事件
MERGE//级联保存或者更新,jpa规范 hibernate为了支持jsr220 后面添加的,调用s ...
1、pojo类编写
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.search.annotations.Analyzer;
import org.hibernat ...
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http ...
1、分页帮助类
public class Page<T> {
//-- 公共变量 --//
public static final String ASC = "asc";
public static final String DESC = "desc";
//-- 分页参数 --//
protected int pageNo = 1;
protected int pageSize = -1;
protected String orderBy = null;
protected String order ...
1、所有Dao标志接口
public interface DataAccessObject {}
2、所有实体标志父类
public class DominObject implements Serializable{}
3、DAO基础接口,包括增删改查等
public interface BaseDao<Entity, PK extends Serializable> extends
DataAcce ...