标签:pre nts string www. actor int www org oid
package com.ehcache; import java.io.Serializable; public class User implements Serializable{ private int id; private String name; public User() { } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } @Override public String toString() { return "User [id=" + id + ", name=" + name + "]"; } }
<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="com.ehcache"> <!-- name属性:哪个类 table属性:对应哪个表,如果不写,默认的表名就是类的简单名称 --> <class name="User" table="tt_user" > <cache usage="read-write" /> <id name="id"> <generator class="native" /> </id> <property name="name" not-null="true" /> </class> </hibernate-mapping>
@Test public void test2() { Session session = sessionFactory.openSession(); session.beginTransaction(); User u1 = session.load(User.class, 1);
//这边注释session关闭后打印u1会报错 no session // Hibernate.initialize(u1); session.getTransaction().commit(); session.close(); System.out.println(u1); // return c1; }
标签:pre nts string www. actor int www org oid
原文地址:https://www.cnblogs.com/Danial7777777/p/9363266.html