保存数据
Hibernate:
insert
into
USER
(NAME, PASSWORD, TYPE)
values
(?, ?, ?)
********************************
根据id查询get方式
Hibernate:
select
user0_.ID as ID1_0_0_,
user0_.NAME as NAME2_0_0_,
user0_.PASSWORD as PASSWORD3_0_0_,
user0_.TYPE as TYPE4_0_0_
from
USER user0_
where
user0_.ID=?
查询没有的id,出现NullPointerException
java.lang.NullPointerException
********************************
根据id查询load方式
Hibernate:
select
user0_.ID as ID1_0_0_,
user0_.NAME as NAME2_0_0_,
user0_.PASSWORD as PASSWORD3_0_0_,
user0_.TYPE as TYPE4_0_0_
from
USER user0_
where
user0_.ID=?
没有设置 lazy="false"
java.lang.ClassCastException: jxust.model.User_$$_javassist_0 cannot be cast to javassist.util.proxy.Proxy
查询没有的id,出现ObjectNotFoundException
org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [jxust.model.User#7]
********************************
HQL方式查询所有 "from User"
Hibernate:
select
user0_.ID as ID1_0_,
user0_.NAME as NAME2_0_,
user0_.PASSWORD as PASSWORD3_0_,
user0_.TYPE as TYPE4_0_
from
USER user0_
HQL方式 模糊查询"from User where name like '%夜%'"
Hibernate:
select
user0_.ID as ID1_0_,
user0_.NAME as NAME2_0_,
user0_.PASSWORD as PASSWORD3_0_,
user0_.TYPE as TYPE4_0_
from
USER user0_
where
user0_.NAME like '%夜%'
********************************
删除
Hibernate:
delete
from
USER
where
ID=?
单独主键外的值,删除无效
如果主键设置了,其他键也设置
其他键的数据要与数据库相同
否则发生异常
org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
********************************
更新数据
Hibernate:
update
USER
set
NAME=?,
PASSWORD=?,
TYPE=?
where
ID=?
********************************