| In our application we use EntityManager.Clear in a method annotated with @transactional although we know it's not best practice ( we'll remove the call to clear()). when performing the same operation in large scale (the operation is done on single element and not in a robust way), we get NullPointerException. stack trace:
java.lang.NullPointerException
at org.hibernate.engine.internal.StatefulPersistenceContext.clear(StatefulPersistenceContext.java:237) ~[hibernate-core-4.3.8.Final.jar:4.3.8.Final]
at org.hibernate.internal.SessionImpl.internalClear(SessionImpl.java:340) ~[hibernate-core-4.3.8.Final.jar:4.3.8.Final]
at org.hibernate.internal.SessionImpl.clear(SessionImpl.java:336) ~[hibernate-core-4.3.8.Final.jar:4.3.8.Final]
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.clear(AbstractEntityManagerImpl.java:1419) ~[hibernate-entitymanager-4.3.8.Final.jar:4.3.8.Final]
at sun.reflect.GeneratedMethodAccessor178.invoke(Unknown Source) ~[?:?]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_60]
at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_60]
at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:344) ~[spring-orm-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at com.sun.proxy.$Proxy79.clear(Unknown Source) ~[?:?]
the stack trace show that the the source of the call is our call to entityManager.clear(). |