spring - why `EntityManager` work,but EntityManagerFactory did not work for me? -
i try use spring+jpa+hibernat
e , try inject entitymanagerfactory
,and later create entitymanger in code.but when use entitymanager.persist(user)
,the user
not saving database
.but when try inject entitymanager
instead of entitymanagerfactory
,it worked !,i not know problem.
you can see question more code.
when using plain entitymanagerfactory
instead of entitymanager
need call createentitymanager
. create new entitymanager
, plain entitymanager
not managed nor detected spring. have start/commit transactions yourself.
when using entitymanager
obtain transactional synchronized instance, managed spring , bound current transaction. no need start / commit transaction yourself.
see jpa section of reference guide.
Comments
Post a Comment