hibernate
奋斗猿。。。
这个作者很懒,什么都没留下…
展开
-
Hibernate笔记------缓存
二级缓存 Hiberante二级缓存 Hibernate的缓存: 一级缓存:session级缓存 二级缓存:sessionFactory级缓存,用处很大(线程级:ehcache) 三级缓存:分布式缓存(进程级:redis) 缓存分类 实体缓存:根据实体的ID进行缓存,缓存的是一个一个的对象 查询缓存:根据HQL查询语句进行缓存,缓存的是结果集。setCacheable(true) 缓存:是很多个map(key, value)组成,使用region来区别 ehcache使用 1.引入ehcac原创 2020-09-29 16:25:48 · 609 阅读 · 0 评论 -
Hibernate笔记-----hql
1、DML风格:批量操作 // HQL的批量修改 String hql = "update Student set name=?1 where age>=?2"; session.createQuery(hql).setParameter(1, "测试").setParameter(2, 38).executeUpdate(); // HQL的批量删除 String hql = "delete from Student where age>=?1"; session.createQuery(h原创 2020-09-23 18:14:46 · 144 阅读 · 0 评论 -
Hibernate 常用注解
一、常用注解 1. @Entity, @Table(一起使用) 2. 主键字段:@Id, @GeneratedValue, @Column 3. 一般字段:@Column 4. 临时字段:@Transient 5. 关联关系字段:一对一,一对多,多对一,多对多 二、@Entity, @Table: 1. @Table(name="xx"):指定映射的表名,如果不指定,默认表名为类名 1. 表名尽量不要有大写字母 2. oracle:不区分大小写(自动变成大写) 3. mysql:默认原创 2020-09-20 17:49:46 · 1174 阅读 · 0 评论 -
Hibernate笔记------ 关联关系
1、一对多:班级与学生 班级(Clazz): @OneToMany(mappedBy = "clazz") private Set<Student> students = new HashSet<>(); 学生(Student): @ManyToOne @JoinColumn(name = "clazz_id") private Clazz clazz; 2、一对一:人与身份证 基于外键的一对一 人(Person): @OneToOne @JoinColumn原创 2020-09-20 17:27:53 · 102 阅读 · 0 评论 -
hibernate 操作——增删改查
User类 @Entity @Table(name = "tb_user") public class User { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @Column(length = 50) private String name; private int age; public Long getId() { return id; } public原创 2020-09-06 15:59:32 · 186 阅读 · 0 评论 -
Hibernate搭建简述
1、加入hibernate框架相关的jar包(数据库版本和驱动版本要匹配) 2、编写hibernate的配置文件:默认文件名称 hibernate.cfg.xml 1) 创建src/hibernate.cfg.xml(hibernate.properties) <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate原创 2020-09-06 15:54:37 · 76 阅读 · 0 评论 -
hibernate Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
在学习hibernate时,进行配置出现这样的问题,不能连接数据库。 ERROR: Could not create connection to database server. Exception in thread "main" org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] at org.原创 2020-08-27 17:20:02 · 606 阅读 · 0 评论