spring - why `EntityManager` work,but EntityManagerFactory did not work for me? -


i try use spring+jpa+hibernate , 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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -