![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Hibernate
文章平均质量分 73
apache988
这个作者很懒,什么都没留下…
展开
-
组件映射配置
1,Employee.javapackage com.model;import java.io.Serializable;public class Employee implements Serializable{ private EmployeeId employeeId; private String address; private int age; public E原创 2013-09-11 10:59:00 · 561 阅读 · 0 评论 -
集合映射配置
Product.javapackage com.model;import java.util.ArrayList;import java.util.HashSet;import java.util.List;import java.util.Set;public class Product { private int id; private String name; p原创 2013-09-13 15:09:01 · 605 阅读 · 0 评论 -
继承映射(单表)
Product.javapackage com.model;public class Product { private int id; private String name; private double price; public int getId() { return id; } public void setId(int id) { this.id =原创 2013-09-13 16:21:22 · 481 阅读 · 0 评论 -
继承映射(多表)
Product.javapackage com.model;public class Product { private int id; private String name; private double price; public int getId() { return id; } public void setId(int id) { this.id =原创 2013-09-16 09:30:30 · 542 阅读 · 0 评论 -
NamedQuery用法
Employee.hbm.xml<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">原创 2013-09-16 17:15:39 · 2626 阅读 · 0 评论 -
映射大字段Blob
BlobObj.javapackage com.model;import java.sql.Blob;public class BlobObj { private int id; private Blob img; public int getId() { return id; } public void setId(int id) { this.id = id;原创 2013-09-17 09:55:45 · 838 阅读 · 0 评论 -
hibernate的缓存
一级缓存一级缓存和session绑定,生命周期只能和session相同。由于session不是线程安全的,它的生命周期最长在一个线程里面,所以使用的频率并不高,作用不是太大。二级缓存和sessionFactory绑定的缓存。核心参数:命中率、过期时间、最大生存时间,最大空间时间,最大缓存数。常用二级缓存框架:OsCache、EhCache、JbossCache。原创 2013-09-17 10:44:20 · 447 阅读 · 0 评论 -
配置二级缓存
hibernate.propertieshibernate.dialect org.hibernate.dialect.MySQLDialecthibernate.connection.driver_class com.mysql.jdbc.Driverhibernate.connection.url jdbc:mysql://localhost:3306/hibernatehibe原创 2013-09-17 11:19:28 · 550 阅读 · 0 评论 -
监控hibernate的二级缓存
默认监控是关闭的,在hibernate.properties中打开监控设置#监控二级缓存hibernate.generate_statistcs true测试: @Test public void t2(){ Session session = HibernateUtil.getInstance().getSession(); session.beginTran原创 2013-09-17 14:05:34 · 584 阅读 · 0 评论 -
many-to-many双向关联映射
Teacher.javapackage com.model;import java.util.HashSet;import java.util.Set;public class Teacher { private int id; private String name; private Set students = new HashSet(); public int ge原创 2013-09-13 14:01:25 · 614 阅读 · 0 评论 -
one-to-many单向关联映射
Employee.javapackage com.model;public class Employee { private int id; private String name; public int getId() { return id; } public void setId(int id) { this.id = id; } public String g原创 2013-09-12 15:17:05 · 618 阅读 · 0 评论 -
many-to-one单向关联映射
Employee.javapackage com.model;public class Employee { private int id; private String name; private Department dept; public int getId() { return id; } public void setId(int id) { this.id原创 2013-09-12 14:54:17 · 634 阅读 · 0 评论 -
联合主键配置
1,实体Employee.javapackage com.model;import java.io.Serializable;public class Employee implements Serializable{ private String empNo; private String empName; private String address; private in原创 2013-09-11 10:51:41 · 770 阅读 · 0 评论 -
hibernate中取得JDBC的connection
hibernate对JDBC进行了封装,向我们提供了很多操作的接口.除了使用这些接口外,我们还可以操作原始的connection连接两种方法: session.doWork(new Work(){ @Override public void execute(Connection connection) throws SQLException { //取到了connec原创 2013-09-11 11:30:04 · 815 阅读 · 0 评论 -
session中的重要方法
*持久化操作session.delete(Object object);//删除一个对象session.get(Class entityType,Serializable id);//根据序列化对象查询对象(始终发出sql语句)session.load(Class entityType,Seriazable id);//根据序列化对象查询对象(采用延迟加载策略)session.me原创 2013-09-11 13:56:00 · 761 阅读 · 0 评论 -
one-to-many双向关联映射
Employee.javapackage com.model;public class Employee { private int id; private String name; private Department dept; public int getId() { return id; } public void setId(int id) { this.原创 2013-09-12 15:51:57 · 659 阅读 · 0 评论 -
hibernate的级联操作cascade
cascade属性值:nonesave-updatedeletealldelete-orphanall-delete-orphan原创 2013-09-13 09:41:43 · 574 阅读 · 0 评论 -
one-to-one双向关联映射
Wife.javapackage com.model;public class Wife { private int id; private String name; private Husband husband; public int getId() { return id; } public void setId(int id) { this.id = id;原创 2013-09-13 10:42:47 · 727 阅读 · 0 评论 -
one-to-one双向关联映射第二种
Wife.javapackage com.model;public class Wife { private int id; private String name; private Husband husband; public int getId() { return id; } public void setId(int id) { this.id = id;原创 2013-09-13 11:15:19 · 589 阅读 · 0 评论 -
hibernate4中对象的四种状态
1,瞬时状态(transient)2,持久化状态(persistent)3,游离状态(detached)原创 2013-09-12 11:06:44 · 1091 阅读 · 0 评论 -
映射枚举类型
Emp.javapackage com.model;public class Emp { private int id; private String name; private WeekDay day; public int getId() { return id; } public void setId(int id) { this.id = id; } p原创 2013-09-17 10:16:16 · 598 阅读 · 0 评论