Hibernate(3)——映射对象标识符(OID)

目录

 

1. Hibernate用对象标识符(OID)来区分对象;

2. Hibernate对象标识符生成策略;


​​​​​​​

1. Hibernate用对象标识符(OID)来区分对象;

package com.java.service;

import com.java.model.Teacher;
import com.java.util.HibernateUtil;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

public class TeacherTest {

    public static void main(String[] args) {
        SessionFactory sessionFactory=HibernateUtil.getSessionFactory();
        Session session=sessionFactory.openSession(); // 生成一个session
        session.beginTransaction(); // 开启事务

        Teacher t1=(Teacher)session.get(Teacher.class, Long.valueOf(1));
        Teacher t2=(Teacher)session.get(Teacher.class, Long.valueOf(2));
        Teacher t3=(Teacher)session.get(Teacher.class, Long.valueOf(1));
        System.out.println(t1==t2);
        System.out.println(t1==t3);

        session.getTransaction().commit(); // 提交事务
        session.close(); // 关闭session
    }
}

Hibernate(3)——映射对象标识符(OID)_第1张图片

 

2. Hibernate对象标识符生成策略;

Hibernate(3)——映射对象标识符(OID)_第2张图片

你可能感兴趣的:(●,架构之美)