Home Web Front-end HTML Tutorial Hibernate一些_方法_@注解_代码示例_html/css_WEB-ITnose

Hibernate一些_方法_@注解_代码示例_html/css_WEB-ITnose

Jun 24, 2016 am 11:34 AM



操作数据库7步骤 :
        1 创建一个SessionFactory对象
        2 创建Session对象
        3 开启事务Transaction : hibernate中,然后数据库操作,都必须是事务的,哪怕是查询
        4 执行数据保存操作(必须提交,才会执行对应的操作方法)
        5 提交事务
        6 关闭Session
                session.close();
                getCurrentSession();不需要手动关闭,opensession需要手动关闭
        7 关闭SessionFactory对象


//第一步
SessionFactory :

1 创建一个SessionFactory对象

    Configuration :
    
       

 //创建Configuration对象
    Configuration configuration = new Configuration().configuer();
    // 4.0之后为了分布式,用了这种设计  链接hibernate框架
        ServiceRegistry serviceRegistry = new ServiceRegistryBuilder()
                .applySettings(configuration.getProperties())
                .buildServiceRegistry();
Copy after login

SessionFactory :

        //创建一个SessionFactor对象
         SessionFactory sessionFactiony = null;
         给SessionFactory对象赋值
            sessionFactory = configuration.buildSessionFactory(serviceRegistry);
 //或  SessionFactory sessionFactiony  = configuration.buildSessionFactory(serviceRegistry);//也行,一样
Copy after login

    
//第二步
Session :
   
    2 创建 Session对象
        //用上面创建好的SessionFactory对象,调用方法,创建一个session对象
    (1) Session session = sessionFactory.getCurrentSession();
    (2) Session session = sessionFactory.opensession();

    getCurrentSession :
        
        创建session对象 如果有,就不创建,如果没有就创建
        Session session = sessionFactory.getCurrentSession();
        并且,自动关闭资源 不用写 session.close();

    opensession :

        创建session对象,别管有没有,都创建
        Session session = sessionFactory.opensession();

        并且,用手动关闭资源,
            session.close();

//第三步
Transaction :

    3 开启事务:hibernate中,然后数据库操作,都必须是事务的,哪怕是查询
        Transaction transaction = session.beginTransaction();

//第四步

    4 执行数据保存操作

    //增
    Save :

     Save();//添加语句方法,生成insert into 表名(列,列)values(?,?)

    //删    
    Delete :

        Delete();//删除语句方法,生成delete from 表 where id=?;

    //改
    Update :

        Update();//修改语句,
            //如果表里面有对应的语句,就生成修改语句update 表名 set (列名,列名)=(列值,列值) where id = ?;

    //查
    Load :

        Load();//查询语句方法,生成查询语句,select * from 表 where id=?
        //如果不访问里面的属性,就只是查询一下,并不会执行到数据库,除非用里面每行对应的对象,去调用一个属性,才会真正的到数据库
        //如果只是提交了,没有访问里面的属性,不会生成查询语句,就是没有对数据库进行操作

    Get :

        Get();//查询语句方法,生成查询语句,select * from 表 where id=?
        //只要提交,就会生成查询语句,

//Get()和Load()的区别   Load()和Get()的区别

        Get() : 只要调用Get()方法并提交,就直接生成查询语句去访问数据库
        Load() : 要调用Load()方法并提交,且,如果没有访问对象里面的属性,不会生成查询语句,也不会操作数据库,一定要获取一下属性,获取对象引用,也算获取属性

//第五步
commit :
     5 提交事务
        transaction.commit();// 提交事务
        transaction是第三步,开启事务的对象

//第六步
Session_close :
    6 关闭Session
        // session.close();//getCurrentSession();不需要手动关闭,opensession需要手动关闭

 //第七步
    SessionFactory_close :
    7 关闭SessionFactory对象
        sessionFactory.close();

//强注解,强注释

  !!!对表来说,只有多的一方保存少的一方的引用,那些设置都是给程序看的,和数据库没有任何关系!!!

@ :
    @Entity 在类名上面加的,用于创建表 默认是类名
        创建实体类和数据标的映射,指定表名
        将一个类声明为一个实体bean(即一个持久化POJO类)。
        @Entity(name="表名")  这样也行,就规定了表名

        @Table :
            @Table(name="表名");也行
     //1 必须得加:
    
    @IdClass 让两个类关联起来 后面是类名  
        在类上面写
        联合主键,就是把主键都写在后面指定的类中
        @IdClass(value=StudentPK.class)
   
        
    @Column 设置当前列在修改的时候,是否可以被修改
        在实体类的get**()方法上写 , 就是对于的列
        @Column(updatable=false)  false就是修改的时候,这个列不能被修改
        里面对应的值 :
            
            name 指定列名(默认是属性名)

            unique 设置该列是否设置唯一约束 默认值是false

            nullable 设置该列的值是否可以为空,默认值是false

            insertable 该列是否作为生成insert语句中的一个列,默认值是true  就是添加的时候,不在此列添加值

            updatetable 该列是否作为生成updatetable语句中的一个列,默认是true  就是修改的时候,不修改此列

            columnDefinition   为这个特定列覆盖sql ddl片段(这可能导致无法在不同数据库间移植)  

            table 定义对应的表 默认为主表

            length 列长度, 默认值255

            precision 列十进制精度(decimal precision) 默认值0   此列最大值为N位  位数

            scale 如果列十进制数值范围(decimal scale)可用,在此设置,默认值0

从数据库查询出来的数据,我都保存在这里
    DTO : 叫Date Traction Object
    VO : 值对象 Value Object


    @SequenceGenerator :
        序列生成器
            @SequenceGenerator(name="sequenceGenerator",sequenceName="Msg_SEQ",initialValue=0,allocationSize=1)//生成器名字,序列的名字,起始值为0,步长为1

    @TableGenerator   生成器 写在类上面
    //用来存放实体类对应的表,下一次要用的id(存放id的表)
    //为主键单独创建一个表,可以跨数据库平台,MySQL主键自增是自己指定,不是外界指定,可能相同

    //有什么好处,能够解决数据跨平台保存的问题,因为不同的数据库平台生成数据的方式不一样,比如primary key(pk),如何还能保证呢?自己写个类库,兼容不同平台
//这里的方式是新建一张表,专门用于保存ID,表名:GENERATOR_TABLE,表里面有两列
//第一列,保存pkColumnName="key", 主键所在列的名字
//第二列,保存Id值 valueColumnName="studentId"
//第三列和第四列保存的是值:第三列是key的值,就是要保存id的表名,第四列要保存的步进值,初始值默认是一
//这就意味着,该表可以为无数的表保存Id值,只要对应的表来去一次值,id默认就会加一.有点像一个序列的集合

    @TableGenerator( //生成器
        name = "student_GEN",//生成器的名字
        table = "GENERATOR_TABLE",    //在数据库中,表的名字
        pkColumnName = "key", //主键所在列的名字
        valueColumnName = "studentId",    //保存下一次,要保存id列的数据,是去这里取得的ID的值
        pkColumnValue = "Student",    //指定要用到Id的那张表
        initialValue=1,             //起始值为1
        allocationSize = 1          //步长为1
        )

    @Id 在实体类的getId()上面强注释
        获取对应的id作为列名,并能在这个方法中,获取id的值
        相当于设置表里面的主键

    @GeneratedValue //在@id和getId()直接设置的  去生成器里面拿值,让每次要添加的数据,ID不相同,不唯一  设置该列自增

    generator="生成器的名字"  //在哪个生成器取Id
    5种格式
        1 Auto   随机
        2 table   生成一个表,存放在表里面
        3 Identity  序列一类的
        4 sequence   序列生成器,生成序列化的数字
        5 自定义   自己写的
    @GeneratedValue(strategy=GenerationType.生成的格式 , generator="生成器的名字")
    @GeneratedValue(strategy=GenerationType.TABLE , generator="student_GEN")

    @OneToOne
        
        要么都写,一个写@oneToone  一个写@ManyToOne
        要么在多的里面写@ManyToOne   多的里面必须要加 unique="true" 设置唯一  就是一对一了
            
        XML :
    @OneToOne(mappedBy="wife")
        //我不保留对方的引用,只让对方保存我的引用,并且,是对方的wife那条属性,保存的是我的引用,
        告诉hibernate我们是一对一关系,但是映射是在husband的wife的属性做的,以那边为标准,这边不用管,但是那边的属性指向的是wife的id
        就是在对面表中,生成一个列,这个列,专门保存本表的id的引用,当本表添加的时候,就让对面表的这个列,生成一个值,当对面表添加的时候,会参考这个列,生成一个ID,当做对面表的ID
            在本实体类中,获取另外一个类的属性的get**()上面写
            @OneToOne
                告诉hibernate我们是一对一关系,但是映射是在husband的wife的属性做的,以那边为标准,这边不用管,但是那边的属性指向的是wife

    @ManyToOne

        告诉hibernate我们是多对一的关系
        
        多对一  必须写在多的里面

    @JoinTable : //更改表的名字和列的名字

    @ManyToMany//多对多

    // 想更改表的名字和列的名字
    @JoinTable(name = "t_s",  // 表名  中间表
            joinColumns = { @JoinColumn(name = "teacher_id") },// 中间表的列名
    inverseJoinColumns = { @JoinColumn(name = "student_id") })//上面的列名指向的是谁,先通过上面指定的列名,找到这个列名,就能找到student表
            
    @JoinColumn
        
        自己指定外键列的名字,还可以指定长度,约束等
        @JoinColumn(name="wifeid") 指定外键名字为wifeid  写在外键列的get外键引用()方法上面

            //在少的表,设置多的表中,保存少的表的引用的列的列名
            //多的表,保存少的表的引用的那个列的列名

    @Embedded
        
           把两个表弄成一个表,且另一个表没有@Entity,写在get**()方法上面
        @Embedded(name="asd")指定别的表,保存当前表的引用的那个列的列名

!!!只有在一对一的时候,才有主键映射和外键映射
//主键映射

        @PrimaryKeyJoinColumn
        在对面引用的列上面加 @PrimaryKeyJoinColumn 就是主键映射
        主键映射 : 不会多生成一个列,添加的时候,会去参照另一个表的主键来生成本表的主键,本表主键和另一个表的主键有关联

//外键映射
        
        @ForeignKeyJoinColumn
         @OneToOne(mappedBy="wife") //我不保留对面的引用,让对面来保存我的引用,并且是保存在对面的wife这个属性,
         //我不保存对面的引用,让对面用wife这个属性来保存我的引用
        
        外键映射 : 多生成一个列,添加的时候,这个新的列会去参照另一个表的主键,让这个列,和另一个表有关联

mappedBy :

    只要是有双向的关系,就必须保持对方的引用,必须有mappendBy(对面)(限于双向) 少的一方必须用set集合保存多的一方的引用,且两边都注明多对以@ManyToOne(多的写) 和@OneToMany(一个的写)

    对表来说,只有多的一方保存少的一方的引用,那些设置都是给程序看的,和数据库没有任何关系

@OneToMany(mappedBy="group",//就是在对面表中,生成一个列,这个列,专门保存本表的id的引用,当本表添加的时候,就让对面表的这个列,生成一个值,当对面表添加的时候,会参考这个列,生成一个ID,当做对面表的ID
            cascade={CascadeType.ALL},//设置级联操作,在什么时候起作用
            fetch=FetchType.EAGER //级联操作的时机,这里默认是Lazy因为是少的一方
            
            )

cascade :

    cascade={CascadeType.ALL/DETACH/MERGE/PERSIST/REFRESH/REMOVE/自定义};
    //设置级联操作在什么时候起作用,就是A的增删改查,B也有改变,就相当于是绑定了事件,后面的值,就是事件,当触发这个事件的时候,就A,B两个表的属性都更新同步,级联操作
        ALL : 是所有操作都级联
        DETACH :
        MERGE : 也就是修改的时候,相当于update,级联
        REMOVE : 删除的时候,级联
        还有自定义
fetch :

    fetch=FetchType.EAGER/LAZY   //这是级联操作的时机,
        EAGER : 的时候,是比如 A里面有个列保存了B的引用,如果这里设置的是EAGER.那取出或者查看的时候,会把这个保存B的引用的那个列也拿出来,

        生成语句 :
        //生成一条查询语句

        LAZY : 的时候,是如果 A里面有个列保存了B的引用,如果这里设置的是LAZY,那取出或者查看的时候,不会把这个保存B的引用的那个列拿出来,只取出别的列,如果在关闭session对象(缓冲)之前,用到那个保存B的引用的那个列,就会再生成一个查询语句,去数据库查询,再把那个列拿出来

         生成语句 :
        //如果用到保存B引用的那个列,就会生成两个查询语句,否则就是生成一个查询语句,并且第一次查询语句中不包括保存B引用的那个列

//执行顺序
@Before/@BerforeClass -- > @Test --> @After/@AfterClass

    @Before :
        
        用于测试类中 , 用它强注释的,是第一个执行的,
        测试方法是成员方法 此方法是公共的,没有返回值的,没有参数列表的,成员方法

    @BerforeClass
        
        用于测试类中 , 用它强注释的,是第一个执行的,
        测试方法是静态方法  此方法是公共的,静态的,没有返回值的,没有参数列表的,静态方法

    @Test :
        
        测试方法 :
            1 公共的 的成员方法
            2 没有返回值
            3 没有形参列表

    @After :
        
        用于测试类中 , 用它强注释的,是最后一个执行的,
        测试方法是成员方法 此方法是公共的,没有返回值的,没有参数列表的,成员方法

    @AfterClass :
        
         用于测试类中 , 用它强注释的,是最后一个执行的,
        测试方法是静态方法  此方法是公共的,静态的,没有返回值的,没有参数列表的,静态方法

//三种状态 :

        瞬时状态(临时状态)--->持久状态(保存到数据库)--->游离状态(保存完成后关闭session对象 (session.close()))
    
    //三种状态的区分关键在于
        1 有没有ID
        2 ID在数据库中有没有
        3 内存中有没有(session缓存)
        
 Transient :

    Transient(瞬时状态) : 内存中一个实体类对象,没有ID,缓存中也没有
    //实例化实体类的时候,就是瞬时状态

 Persistent :

    Persistent(持久状态) : 内存中有,缓存中有,数据库中有(ID)
    //保存到数据库中,就是持久状态

 Detached :

    Detached(游离状态) : 内存有,缓存没有,数据库有,ID
    //关闭session对象之后(session.close()),就是游离状态

    //这三种状态需要关注的问题是在该状态下,如果进行数据库操作会发生什么结果,比如改变属性的值会不会发出update语句
        
        瞬时状态 : 不会发出update语句
        持久状态 和 游离状态 都会发出update语句
    
//联合主键

    @EmbeddedId : 嵌入的,写在实体类中,主键类的引用上面,对应的get主键类();方法上面
    @Embeddable : 可被嵌入的,该类作为另一个类的一部分,写在主键类中,
    1
    @IdClass :
    比如说是两个主键,id和name列,就在实体类中的getId()和getName()上面,加@id 声明主键,并且在类上面写 @IdClass(写的主键类名.class),    再把这两个主键写在一个实体类中,
    但是这个存有多个主键的实体类,必须实现serializable这个接口
    在主键类的类上面,不用写@Embeddable

  2
    @EmbeddedId :
    或者是本类中不写id和name,但是有主键类的引用,然后在主键类对应的get主键类();方法上面,写个@EmbeddedId,就行了
    但是在主键类的类上面,要写@Embeddable
        


//关联两个表

    new SchemaExport(new AnnotationConfiguration().configure()).create(false, true);

//面向对象的形式 :

HQL :

Query :

//---------------------------模糊查询
        
QBE : 
        Topic tExample = new Topic();//自己写的类
        //创建类对象,就是一个表中的一个行的属性
        tExample.setTitle("T_");//往对象里面设置属性(set***()方法) , 像T_的,一个典型,只能是一个确定值的对象,用于搜索,

        Example e = Example.create(tExample).ignoreCase().enableLike();// 静态方法 添加模糊查询的方法
        Criteria c = session.createCriteria(Topic.class)//给指定类(表)添加约束
                .add(Restrictions.gt("id", 2))//id属性大于2的
                .add(Restrictions.lt("id", 8))//id属性小于8的
                .add(e);//上面写好的模糊查询  "T_"

//-----------------1+N

//1+N:只要查询当前对象,他就会查询别的
    //可以多表查询,可以解决1+N问题
    //设置为Lazy
@BatchSize : 

        @BatchSize(size = 5);////@BathSize: 默认是一个一个抓取,这里可以指定每次抓取的个数
        写在类上面

left_outer_join_fetch  : 

    (用iterator(迭代器)就不能使用join)

     Query q = session.createQuery("from Topic t left outer join fetch t.category c ");//Topic是对象,对象里面有个属性是另外一个表的引用,t.category就能获得另外一个类对应的表和其中的属性

        List topics = q.list();//把查询出来的值,封装到对应的对象中,再封装到list集合中
        简写 : 
            List topics = session.createQuery("from Topic t left outer join fetch t.category c");

前提 : 必须有一个对象(表)中的属性(列),保存的是另一个表的引用
    如 : Topic对象中 有个属性 保存了Category的引用

    如 :  List topics = session.createQuery("from 表1 别名(t) left outer join fetch t.表名2 别名(c)");

    inner_join_fetch : 

         List topics = session.createQuery("from Topic t inner join fetch t.category c");

    left_outer_join_fetch :  

    结果集 : 
        表2在表1的左边
         //先查询Topic对象对应的表,再通过topic找到category对应的表,都查询出来,并且,category对应的表,查询出来并显示在Topic的左面 (相当于把两个表的结果集,合并成一个表,一个在左面,一个在右面)
        List topics = session.createQuery("from Topic t left outer join fetch t.category c");

    right_outer_join_fetch : 

    结果集 : 
        表2在表1的右边
         //先查询Topic对象对应的表,再通过topic找到category对应的表,都查询出来,并且,category对应的表,查询出来并显示在Topic的右面 (相当于把两个表的结果集,合并成一个表,一个在左面,一个在右面)
         List topics = session.createQuery("from Topic t right outer join fetch t.category c");

iterator : 

        // iterator: 如果使用不允许使用join
        //迭代器,把查询的数据直接用迭代器遍历
        Iterator<泛型,一般用于对象名> categories = session.createQuery("from 对象 别名").iterate();//
        Iterator categories = session.createQuery("from Category c").iterate();//

        while (categories.hasNext()) {//hasNext(),是问下一位还有没有元素,返回值为boolean型,true/false
            Category c = categories.next();//next()是取得下一位元素的值,
            System.out.println(c.getName());//因为里面都是对象,所以可以通过上面获取的对象的引用,去访问对象里面的属性
        }

Cacheable : 

        开启缓存,要和ehcache.xml一起使用
        List categories = session.createQuery("from Category").setCacheable(true).list();//查询Category对象对应的表,然后放入缓存中,封装到list集合中
        setCacheable(true);//开启缓存

以上就是Hibernate一些_方法_@注解_代码示例_html/css_WEB-ITnose的内容,更多相关内容请关注PHP中文网(www.php.cn)!


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to integrate Hibernate in SpringBoot project How to integrate Hibernate in SpringBoot project May 18, 2023 am 09:49 AM

Integrating Hibernate in SpringBoot Project Preface Hibernate is a popular ORM (Object Relational Mapping) framework that can map Java objects to database tables to facilitate persistence operations. In the SpringBoot project, integrating Hibernate can help us perform database operations more easily. This article will introduce how to integrate Hibernate in the SpringBoot project and provide corresponding examples. 1.Introduce dependenciesIntroduce the following dependencies in the pom.xml file: org.springframework.bootspring-boot-starter-data-jpam

Java Errors: Hibernate Errors, How to Handle and Avoid Java Errors: Hibernate Errors, How to Handle and Avoid Jun 25, 2023 am 09:09 AM

Java is an object-oriented programming language that is widely used in the field of software development. Hibernate is a popular Java persistence framework that provides a simple and efficient way to manage the persistence of Java objects. However, Hibernate errors are often encountered during the development process, and these errors may cause the program to terminate abnormally or become unstable. How to handle and avoid Hibernate errors has become a skill that Java developers must master. This article will introduce some common Hib

What are the differences between hibernate and mybatis What are the differences between hibernate and mybatis Jan 03, 2024 pm 03:35 PM

The differences between hibernate and mybatis: 1. Implementation method; 2. Performance; 3. Comparison of object management; 4. Caching mechanism. Detailed introduction: 1. Implementation method, Hibernate is a complete object/relational mapping solution that maps objects to database tables, while MyBatis requires developers to manually write SQL statements and ResultMap; 2. Performance, Hibernate is possible in terms of development speed Faster than MyBatis because Hibernate simplifies the DAO layer and so on.

How to perform bulk insert update operations in Hibernate? How to perform bulk insert update operations in Hibernate? Aug 27, 2023 pm 11:17 PM

In this article, we will see how to perform bulk insert/update in Hibernate. Whenever we execute a sql statement, we do it by making a network call to the database. Now, if we have to insert 10 entries into the database table, then we have to make 10 network calls. Instead, we can optimize network calls by using batch processing. Batch processing allows us to execute a set of SQL statements in a single network call. To understand and implement this, let us define our entity − @EntitypublicclassParent{@Id@GeneratedValue(strategy=GenerationType.AUTO)

What is the mapping method of one-to-many and many-to-many relationships in Java Hibernate What is the mapping method of one-to-many and many-to-many relationships in Java Hibernate May 27, 2023 pm 05:06 PM

Hibernate's one-to-many and many-to-many Hibernate is an excellent ORM framework that simplifies data access between Java applications and relational databases. In Hibernate, we can use one-to-many and many-to-many relationships to handle complex data models. Hibernate's one-to-many In Hibernate, a one-to-many relationship means that one entity class corresponds to multiple other entity classes. For example, an order can correspond to multiple order items (OrderItem), and a user (User) can correspond to multiple orders (Order). To implement a one-to-many relationship in Hibernate, you need to define a collection attribute in the entity class to store

In-depth understanding of the Java framework technology stack: explore common Java frameworks such as Spring MVC, Hibernate, MyBatis, etc. In-depth understanding of the Java framework technology stack: explore common Java frameworks such as Spring MVC, Hibernate, MyBatis, etc. Dec 26, 2023 pm 12:50 PM

Java framework technology stack: Introducing commonly used Java frameworks, such as SpringMVC, Hibernate, MyBatis, etc. With the continuous development of Java, more and more frameworks have been developed to simplify the development process. Among them, SpringMVC, Hibernate, MyBatis, etc. are one of the most commonly used frameworks in Java development. This article will introduce the basic concepts and usage of these frameworks to help readers better understand and apply these frameworks. First, let’s introduce Sp

Introduction to Hibernate framework in Java language Introduction to Hibernate framework in Java language Jun 10, 2023 am 11:35 AM

Hibernate is an open source ORM framework that binds the data mapping between relational databases and Java programs to each other, making it easier for developers to access data in the database. Using the Hibernate framework can greatly reduce the work of writing SQL statements and improve the development efficiency and reusability of applications. Let's introduce the Hibernate framework from the following aspects. 1. Advantages of the Hibernate framework: object-relational mapping, hiding database access details, making development

How does Hibernate second level cache work? How does Hibernate second level cache work? Sep 14, 2023 pm 07:45 PM

Caching helps reduce database network calls when executing queries. Level 1 cache and session linking. It is implemented implicitly. The first level cache exists until the session object exists. Once the session object is terminated/closed, there will be no cached objects. Second level cache works for multiple session objects. It is linked with the session factory. Second level cache objects are available to all sessions using a single session factory. These cache objects will be terminated when a specific session factory is closed. To implement the second level cache we need to add the following dependencies to use the second level cache. <!--https://mvnrepository.com/artifact/net.sf.ehcache/ehcache--><de

See all articles