EntityManager常用API简单备忘

    1)find(), getReference() 获得实体,类似getById。
    2)persist() 将数据保存到数据库中,传递的参数必须是实体bean,类似insert。
    3)当实体正在被容器管理时,你可以调用实体的set方法对数据进行修改,在容器决定flush时(这个由container自行判断),更新的数据才会同步到数据库,而不是马上同步到数据库。如果你希望修改后的数据马上同步到数据库,你可以调用EntityManager.flush()方法。
    当实体已经脱离容器的管理,则可以使用EntityManager.merge() update。
    4)remove() 参数必须是实体bean,在cascade=CascadeType.ALL或cascade=CascadeType.REM
OVE的情况下可以级联删除对象。
    5)createQuery(hql) createNativeQuery createNamedQuery


参考: http://blog.csdn.net/vicky_fish/article/details/7361883

你可能感兴趣的:(jpa,EntityManager)