????????how??Hibernate?????????????????
????1.  ???????????:
????evit(Object obj)  ?????????????????????????????????????????????????????????????????????????????????????
????clear()  ??????????е????г?????????????????????????????
????contains(Object obj) ?ж?????????????????????????С?
????flush() ????????????????????????????????????????
????2.??????????? save()????session???????save()??????????????????????????session??????С? get()??load()????session???????get()??load()??????????????????????????????????session??????С? ???HQL??QBC?????????в???????
public class Client
{
public static void main(String[] args)
{
Session session = HibernateUtil.getSessionFactory().openSession();
Transaction tx = null;
try
{
/*???????????*/
tx = session.beginTransaction();
/*????????л??id="402881e534fa5a440134fa5a45340002"??Customer????*/
Customer customer1 = (Customer)session.get(Customer.class?? "402881e534fa5a440134fa5a45340002");
System.out.println("customer.getUsername is"+customer1.getUsername());
/*??????*/
tx.commit();
System.out.println("-------------------------------------");
/*?????????????*/
tx = session.beginTransaction();
/*????????л??id="402881e534fa5a440134fa5a45340002"??Customer????*/
Customer customer2 = (Customer)session.get(Customer.class?? "402881e534fa5a440134fa5a45340002");
System.out.println("customer2.getUsername is"+customer2.getUsername());
/*??????*/
tx.commit();
System.out.println("-------------------------------------");
/*???????get()?????????????????????????*/
System.out.println("customer1 == customer2 result is "+(customer1==customer2));
}
catch (Exception e)
{
if(tx!=null)
{
tx.rollback();
}
}
finally
{
session.close();
}
}
}
???????
Hibernate:
select
customer0_.id as id0_0_??
customer0_.username as username0_0_??
customer0_.balance as balance0_0_
from
customer customer0_
where
customer0_.id=?
customer.getUsername islisi
-------------------------------------
customer2.getUsername islisi
-------------------------------------
customer1 == customer2 result is true
??????????????????????SELECT SQL???????customer1 == customer2 result is true???????????????????????????????????????ε???get()?????? Hibernate???????????????иò????????????У?Hibernate????SELECT???????????????????????????????????У?????′?????????ε???get()??????Hibernate???????????????иò???????????????иò???????????????????????????????м?????