NullPointerEx at org.hibernate.engine.StatefulPersistenceContext line 1401 - java

I have asked this question in Hibernate forum for a week without an anwser - https://forum.hibernate.org/viewtopic.php?f=1&t=1011634. I am really stuck here and hopefully can get help here. I got NullPointerException from org.hibernate.engine.StatefulPersistenceContext.
My hibernate dependency is as follows:
org.hibernate
hibernate-entitymanager
3.5.6-Final
The exception stack is below:
2011-07-04 07:06:38,691 DEBUG [http-8080-2] mobi.esca.mobile.remoting.HttpInvokerServiceExporter (HttpInvokerServiceExporter.java:168) - java.lang.NullPointerException
java.lang.NullPointerException
at org.hibernate.engine.StatefulPersistenceContext.replaceDelayedEntityIdentityInsertKeys(StatefulPersistenceContext.java:1401)
at org.hibernate.action.EntityIdentityInsertAction.postInsert(EntityIdentityInsertAction.java:117)
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:89)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:267)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:259)
at org.hibernate.engine.ActionQueue.executeInserts(ActionQueue.java:169)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:287)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:204)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:130)
at org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:69)
at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:179)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:135)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:61)
at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:800)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:774)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:778)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:668)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:365)
at $Proxy138.persist(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:240)
at $Proxy59.persist(Unknown Source)
at org.springframework.orm.jpa.JpaTemplate$5.doInJpa(JpaTemplate.java:264)
at org.springframework.orm.jpa.JpaTemplate.execute(JpaTemplate.java:183)
at org.springframework.orm.jpa.JpaTemplate.persist(JpaTemplate.java:262)
at mobi.esca.persistence.GenericJPARepository.persist(GenericJPARepository.java:153)
at mobi.esca.persistence.GenericJPARepository.persistAll(GenericJPARepository.java:161)
at mobi.esca.mars.application.UsageManager.logUsageStats(UsageManager.java:43)
at mobi.esca.mars.interfaces.mobile.EndUserController.reportStats(EndUserController.java:259)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:196)
at $Proxy137.reportStats(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at mobi.esca.mobile.remoting.RemoteInvocationAdaptor.invoke(RemoteInvocationAdaptor.java:89)
at mobi.esca.mobile.remoting.RemoteInvocationAdaptor.proceed(RemoteInvocationAdaptor.java:54)
at mobi.esca.mobile.remoting.FilterChain.doFilter(FilterChain.java:59)
at mobi.esca.mobile.remoting.MethodInvocationRateFromUserProtection.doFilter(MethodInvocationRateFromUserProtection.java:56)
at mobi.esca.mobile.remoting.FilterChain.doFilter(FilterChain.java:56)
at mobi.esca.mobile.remoting.MethodInvocationRateFromIpProtection.doFilter(MethodInvocationRateFromIpProtection.java:57)
at mobi.esca.mobile.remoting.FilterChain.doFilter(FilterChain.java:56)
at mobi.esca.mars.interfaces.mobile.ClientVersionChecker.doFilter(ClientVersionChecker.java:41)
at mobi.esca.mobile.remoting.FilterChain.doFilter(FilterChain.java:56)
at mobi.esca.mobile.remoting.AuthenticationFilter.doFilter(AuthenticationFilter.java:37)
at mobi.esca.mobile.remoting.FilterChain.doFilter(FilterChain.java:56)
at mobi.esca.mobile.remoting.HttpInvokerServiceExporter.invokeAndCreateResult(HttpInvokerServiceExporter.java:201)
at mobi.esca.mobile.remoting.HttpInvokerServiceExporter.handleRequestInternal(HttpInvokerServiceExporter.java:128)
at mobi.esca.mobile.remoting.HttpInvokerServiceExporter.handleRequest(HttpInvokerServiceExporter.java:102)
at org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:49)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:113)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
I am looking at the line 1401 of StatefulPersistenceContext.java file:
1396 public void replaceDelayedEntityIdentityInsertKeys(EntityKey oldKey, Serializable generatedId) {
1397 Object entity = entitiesByKey.remove( oldKey );
1398 EntityEntry oldEntry = ( EntityEntry ) entityEntries.remove( entity );
1399 parentsByChild.clear();
1400
1401 EntityKey newKey = new EntityKey( generatedId, oldEntry.getPersister(), getSession().getEntityMode() );
1402 addEntity( newKey, entity );
so the possible null object here could be oldEntry, right? Could anyone tell me when oldEntry can become null? What can i do to fix the problem?
Your help will be highly appreciated.
Many thanks,
Cheng Wei
Hi Moe,
Thanks for your reply. The exception are happening randomly in various methods in our system now, and i can not recreate it by unit test. I will give a simplest code from a method.
#Controller
public class EndUserController implements EndUserService, InvocationContextRequired
{
#Override
public void reportStats(UsageStatsDTO usageStatsDTO) throws ClientVersionOutOfDateException
{
log.debug("enter UsageReportController.reportStats()");
UsageStats usageStats = usageStatsDTO.asUsageStats(getEndUser());
usageManager.logUsageStats(usageStats);
if(usageStats.hasAppStartEvent())
{
endUserManager.updateClientVersion(getEndUser(), getClientVersion());
}
log.debug("exit UsageReportController.reportStats()");
}
......
}
#Service
public class UsageManager
{
#Autowired
private CallEventRepository callEventRepository;
#Autowired
private AppStartEventRepository appStartEventRepository;
#Autowired
private InviteEventRepository inviteEventRepository;
#Transactional
public void logUsageStats(UsageStats usageStats)
{
if (usageStats.hasCallEvent())
{
callEventRepository.persistAll(usageStats.getCallEvents());
}
if (usageStats.hasAppStartEvent())
{
appStartEventRepository.persistAll(usageStats.getAppStartEvents());
}
if (usageStats.hasInviteEvent())
{
inviteEventRepository.persistAll(usageStats.getInviteEvents());
}
}
......
}
public class GenericJPARepository<T, ID extends Serializable>
implements GenericRepository<T, ID>
{
#Override
public T persist(T entity)
{
getJpaTemplate().persist(entity);
return entity;
}
#Override
public void persistAll(Collection<T> entities)
{
for(T entity : entities)
{
persist(entity);
}
}
......
}
And all RepositoryImpl classes are the subclasses(CallEventRepository,AppStartEventRepository,InviteEventRepository) of GenericJPARepository.
Many thanks,
Cheng Wei
Can problem be caused by i detach an entity? endUserRepository.detach(detatchedEndUser); But UsageStats, the object to be persisted, does not reference to detatchedEndUser.
Thanks Moe and Maurice, Appreciate your help. I finally find the problem. the following code caused the problem:
EndUser toBePersistedEndUser = endUserRepository.persist(new EndUser(remoteEndUser));
endUserRepository.detach(toBePersistedEndUser );
return toBePersistedEndUser;
Also, i think i reveal a bug for hibernate here.
Problem solved, Many thanks,
Cheng Wei

Well, either oldEntry is null, or getSession() returns null.
Obviously, oldEntry will be null if the entityEntries doesn't contain the entry removed from entitiesByKey. It could also happen if the equals() method for EntityEntry is incorrectly implemented.

Related

Nested exception is org.hibernate.exception.GenericJDBCException: could not execute statement

I was kind of roped into using maven, Hibernate, spring and JPA repositories in a small project. I cheerfully assumed that information found here
http://docs.spring.io/spring-data/jpa/docs/1.4.2.RELEASE/reference/html/jpa.repositories.html
will be enough to create at least a simple application. Unluckily that's not the case. I've managed to read data from a MySQL database, but as for now have been unable to insert any data.
Here is a simple 'User' model class.
#Entity
#Table(name = "ctuser")
public class User implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private long uid;
#Column(name = "Gmail", nullable = false)
private String gmail;
public String getGmail() {
return gmail;
}
public void setGmail(String gmail) {
this.gmail = gmail;
}
#Override
public String toString() {
return getGmail();
}
}
I've created an appropriate repository interface...
package put.io.come_together.service.persistance.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import put.io.come_together.model.User;
public interface UserRepository extends JpaRepository<User, Long> {
User findUserByUid(long uid);
User save (User obj);
}
...an interface for the service...
public interface UserService {
User getUser(long uid);
User addUser(User obj);
List<User> getAll();
}
...and implementation of the interface.
#Service
public class UserServiceImpl implements UserService {
private final UserRepository userRepository;
#Autowired
public UserServiceImpl(UserRepository userRepository) {
this.userRepository = userRepository;
}
#Override
public User getUser(long uid) {return userRepository.findUserByUid(uid);
}
#Transactional
#Override
public User addUser(User obj) {return this.userRepository.saveAndFlush(obj);}
#Override
public List<User> getAll() {
return userRepository.findAll();
}
Finally I'm trying to present as the data as well as insert something into database.
#Controller
public class HomePageController {
#Autowired
private UserService userService;
private static final String USER_MAP_KEY = "groups";
private static final String USER_LIST_TEMPLATE_NAME = "groupList";
#RequestMapping("/")
String hello(Map<String, Object> model) {
User osoba = new User();
osoba.setGmail("ADAMWEST");
userService.addUser(osoba);
List<User> userGroupsList = userService.getAll();
model.put(USER_MAP_KEY, userGroupsList);
return USER_LIST_TEMPLATE_NAME;
}
}
If I leave out the userService.addUser(osoba); line, everything works fine. I can see the data read from the database neatly laid out. But when I try to actually use the .addUser() method my localhost puts out a white label error page.
White label Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Sun Apr 19 09:36:52 CEST 2015
There was an unexpected error (type=Internal Server Error, status=500).
could not execute statement; nested exception is org.hibernate.exception.GenericJDBCException: could not execute statement
Would you kindly tell me what is it that I'm doing wrong? I've been trying to solve the problem for some time now, and thoroughly lost hope.
Here is the stack trace of the exception. The error concerns field 'UID' not having a default value, but I marked it as an #Id field. I also dropped the entire database and set it up again, seeing as it helped someone with a similar problem.
java.sql.SQLException: Field 'UID' doesn't have a default value
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:996)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3887)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3823)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2435)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2582)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2530)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1907)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2141)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2077)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2062)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:208)
at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:96)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:58)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3032)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3558)
at org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:98)
at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:492)
at org.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:197)
at org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:181)
at org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:216)
at org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:324)
at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:
288)
at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:194)
at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:125
)
at org.hibernate.jpa.event.internal.core.JpaPersistEventListener.saveWithGeneratedId(JpaPersistEventListener.jav
a:84)
at org.hibernate.event.internal.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:2
06)
at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:149)
at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:75)
at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:811)
at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:784)
at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:789)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:1181)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(Extend
edEntityManagerCreator.java:344)
at com.sun.proxy.$Proxy78.persist(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEnti
tyManagerCreator.java:291)
at com.sun.proxy.$Proxy78.persist(Unknown Source)
at org.springframework.data.jpa.repository.support.SimpleJpaRepository.save(SimpleJpaRepository.java:407)
at org.springframework.data.jpa.repository.support.SimpleJpaRepository.saveAndFlush(SimpleJpaRepository.java:421
)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.exec
uteMethodOn(RepositoryFactorySupport.java:416)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doIn
voke(RepositoryFactorySupport.java:401)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invo
ke(RepositoryFactorySupport.java:373)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$DefaultMethodInvokingMethodIntercep
tor.invoke(RepositoryFactorySupport.java:486)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterce
ptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspec
tSupport.java:281)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTransla
tionInterceptor.java:136)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingM
ethodIntercceptor.invoke(CrudMethodMetadataPostProcessor.java:122)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
at com.sun.proxy.$Proxy80.saveAndFlush(Unknown Source)
at put.io.come_together.service.persistance.impl.UserServiceImpl.addUser(UserServiceImpl.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:
190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterce
ptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspec
tSupport.java:281)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
at com.sun.proxy.$Proxy83.addUser(Unknown Source)
at put.io.come_together.controller.HomePageController.hello(HomePageController.java:29)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:13
7)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletIn
vocableHandlerMethod.java:110)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(Request
MappingHandlerAdapter.java:777)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMapp
ingHandlerAdapter.java:706)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.j
ava:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1086)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:659)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1558)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1515)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
You said Hibernate that the ID was autogenerated using the strategy AUTO. This strategy, with MySQL, consists in letting the database generate the ID using an auto-increment column. So if you haven't defined uid as auto-increment, that won't work.

xCP2.0 Java Service not working - IDfSession is null

I'm currently working on a xCP 2.0 project with Documentum 7.0 and I'm trying to run a Java Service inside a workflow. The Java Service works alright when the function I use does no more than return a "some_string" String. But as soon as I try the actual thing and use documentum specific Objects like:
IDfSession mySession = getSession();
I get these exceptions right here:
java.lang.RuntimeException: Could not invoke the method 'test' from
interface 'class com.gemp1.Test' from BOF module 'gemp1_xCPJava' in
Process Template: 'Peticion de Nuevo Producto v2' - Activity: 'Execute
Java Service'. Workitem: '4a015abd80004959' Workflow: 'Peticion de
Nuevo Producto v2 2014-12-18' - '4d015abd8000411e' Activity: 'Execute
Java Service' - '4c015abd8002e358' Process: 'Peticion de Nuevo
Producto v2' - '4b015abd8002c56c' java.lang.Exception:
java.lang.RuntimeException: Could not invoke the method 'test' from
interface 'class com.gemp1.Test' from BOF module 'gemp1_xCPJava' at
com.documentum.bps.outbound.AbstractService.execute(AbstractService.java:98)
at
com.documentum.bpm.services.BPSIntegrationFramework.executeService(BPSIntegrationFramework.java:260)
at
com.documentum.bpm.services.BPSIntegrationFramework.executeMethod(BPSIntegrationFramework.java:92)
at
com.documentum.bpm.services.BPSIntegrationMethod.executeMethod(BPSIntegrationMethod.java:26)
at
com.documentum.bpm.rtutil.GenericWorkflowMethod.execute(GenericWorkflowMethod.java:129)
at
com.documentum.bpm.rtutil.GenericWorkflowMethod.execute(GenericWorkflowMethod.java:355)
at
com.documentum.bpm.rtutil.GenericWorkflowMethod.execute(GenericWorkflowMethod.java:70)
at com.documentum.mthdservlet.DfMethodRunner.runIt(Unknown Source)
at com.documentum.mthdservlet.AMethodRunner.runAndReturnStatus(Unknown
Source) at com.documentum.mthdservlet.DoMethod.invokeMethod(Unknown
Source) at com.documentum.mthdservlet.DoMethod.doPost(Unknown
Source) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:637) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at
org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
at
org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
at
org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
at
org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at
org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
at
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:662) Caused by:
java.lang.RuntimeException: Could not invoke the method 'test' from
interface 'class com.gemp1.Test' from BOF module 'gemp1_xCPJava' at
com.documentum.bps.outbound.bof.runtime.BOFClient.invokeMethod(BOFClient.java:121)
at
com.documentum.bps.outbound.bof.runtime.BofModuleService.executeServiceOperation(BofModuleService.java:133)
at
com.documentum.bps.outbound.AbstractService.executeServiceInternal(AbstractService.java:122)
at
com.documentum.bps.outbound.AbstractService.execute(AbstractService.java:79)
... 32 more Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597) at
com.documentum.bps.outbound.bof.runtime.BOFClient.invokeMethod(BOFClient.java:112)
... 35 more Caused by: java.lang.NullPointerException at
com.documentum.fc.client.DfSingleDocbaseModule.getSession(DfSingleDocbaseModule.java:58)
at com.gemp1.Test.test(Test.java:11) ... 40 more
My Java class:
package com.gemp1;
import com.documentum.fc.client.*;
import com.documentum.fc.common.DfException;
public class Test extends DfSingleDocbaseModule {
public String test() {
String result = "Hello12345";
return result;
}
public String[] getUsers() throws DfException {
String docbaseUsers[] = new String[200];
IDfCollection coll = null;
IDfSession mySession = getSession();
String myQuery = "select user_name from dm_user";
IDfQuery myDFQuery = new DfQuery(myQuery);
coll = myDFQuery.execute(mySession, IDfQuery.DF_QUERY);
int i=0;
while (coll.next()) {
docbaseUsers[i] = coll.getString("user_name");
i++;
}
return docbaseUsers;
}
}
And finally my javamodule file:
<?xml version="1.0" encoding="UTF-8"?>
<nsJavaModule:JavaModule xmlns:nsJavaModule="http://xcp.emc.com/javamodule" urn="urn:gemp1:com.emc.xcp.artifact.javamodule.category:Artifacts/Java Modules/xCPJava.javamodule" categoryId="com.emc.xcp.artifact.javamodule.category" name="xCPJava" label="xCPJava" implementationClass="com.gemp1.Test">
<implementationJars contentPath="content/modules/xCPJava.jar"/>
<implementationJars contentPath="content/modules/dfc.jar"/>
</nsJavaModule:JavaModule>
Am I missing something?

java.lang.ClassCastException: [Ljava.lang.Object;

I have two functions in my application and after executing queries got an exception
java.lang.ClassCastException: [Ljava.lang.Object;
java.lang.ClassCastException: [Ljava.lang.Object;
at org.openmrs.module.scheduler.impl.SchedulerDWR.fetchUserStatus(SchedulerDWR.java:2011)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.directwebremoting.impl.ExecuteAjaxFilter.doFilter(ExecuteAjaxFilter.java:34)
at org.directwebremoting.impl.DefaultRemoter$1.doFilter(DefaultRemoter.java:428)
at org.directwebremoting.impl.DefaultRemoter.execute(DefaultRemoter.java:431)
at org.directwebremoting.impl.DefaultRemoter.execute(DefaultRemoter.java:283)
at org.directwebremoting.servlet.PlainCallHandler.handle(PlainCallHandler.java:52)
at org.directwebremoting.servlet.UrlProcessor.handle(UrlProcessor.java:101)
at org.directwebremoting.servlet.DwrServlet.doPost(DwrServlet.java:146)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:718)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.openmrs.web.MyTimerFilter.doFilter(MyTimerFilter.java:69)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.openmrs.web.filter.GZIPFilter.doFilterInternal(GZIPFilter.java:61)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.openmrs.module.web.filter.ModuleFilterChain.doFilter(ModuleFilterChain.java:77)
at org.openmrs.module.web.filter.ModuleFilter.doFilter(ModuleFilter.java:59)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.openmrs.web.filter.OpenmrsFilter.doFilterInternal(OpenmrsFilter.java:112)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:97)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:111)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:865)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1555)
at java.lang.Thread.run(Thread.java:662)
These are functions
1
public int fetchUserStatus(String provider)
{
try
{
SchedulerService hService = (SchedulerService)Context.getService(SchedulerService.class);
List<ModuleUser> lst=hService.fetchUserStatus(id);
for(ModuleUser m:lst)//exception in this line
{
int userid=((ModuleUser) m).getUserId();
if(userid==id)
{
status=((ModuleUser) m).getUserStatus();
System.out.println("Inside for"+status);
}
}
System.out.println("status update"+status);
return status;
}
catch(Exception e)
{
e.printStackTrace();
return 2;
}
}
FUNCTION 2
public List<ModuleUser> fetchUserStatus(int id) {
try
{
session=sessionFactory.getCurrentSession();
SQLQuery m=session.createSQLQuery("select * from users");
return m.list();
}
catch(Exception e)
{
e.printStackTrace();
return null;
}
}
Can anyone suggest what is the wrong with the code?
Raw query in this case returns scalar values:
List<Object[]>
where array contains raw columns from result query.
Probably you want something like this:
SQLQuery m=session.createSQLQuery("select * from users").addEntity(ModuleUser.class);
Is ModuleUser a mapped #Entity? If yes use HQL instead of native query
List<ModuleUser> users = session.createQuery("from ModuleUser").list()
Else if you are forced to native SQL use #aim solution

method <init>()V not found while creating an object of a class

I have a class NotifyBuilderUtil, within which I am trying to create an object of another class CustomEmailNotification. However, while creating the object, I am getting an error:
java.lang.NoSuchMethodError: net.mail.CustomEmailNotification: method <init>()V not found
package org.module.definition.notify;
...
import net.mail.CustomEmailNotification;
...
public class NotifyBuilderUtil implements InitializingBean {
private static NotifyBuilderUtil instance;
public NotifyBuilderUtil() {
if(instance != null) throw new SingletonViolationException(NotifyBuilderUtil.class);
instance = this;
}
...
...
public static void buildElements(DefinableEntity entity, Element item, Notify notifyDef, Writer writer, NotifyVisitor.WriterType writerType, Map params, boolean processItem) {
...
String flagElementPath = "./notify";
Element flagElem = (Element) nextItem.selectSingleNode(flagElementPath);
Map oArgs = DefinitionUtils.getOptionalArgs(flagElem);
NotifyVisitor visitor = new NotifyVisitor(entity, notifyDef, customItem, writer, writerType, params);
CustomEmailNotification cen = new CustomEmailNotification();
cen.constructInternalWriter(entity, visitor, flagElem, oArgs);
...
}
}
The CustomEmailNotification :
public class CustomEmailNotification {
private static Map timeFieldMap = null;
public static Writer internalWriter = null;
public static Writer externalWriter = null;
Writer writer;
public CustomEmailNotification() {
timeFieldMap = new HashMap();
}
...
public static void constructInternalWriter(DefinableEntity entity, NotifyVisitor visitor, Element flagElement, Map oArgs) {
...
...
}
}
The error message is :
ERROR [http-8086-1] [org.kablink.teaming.spring.web.portlet.DispatcherPortlet] - Could not complete request
javax.portlet.PortletException: Error occured during request processing: net.mail.CustomEmailNotification: method <init>()V not found
at org.springframework.web.portlet.DispatcherPortlet.doActionService(DispatcherPortlet.java:662)
at org.springframework.web.portlet.FrameworkPortlet.processRequest(FrameworkPortlet.java:519)
at org.springframework.web.portlet.FrameworkPortlet.processAction(FrameworkPortlet.java:460)
at org.kablink.teaming.portletadapter.servlet.PortletAdapterController.handleRequestInternal(PortletAdapterController.java:105)
at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at org.kablink.teaming.portletadapter.servlet.PortletAdapterServlet.service(PortletAdapterServlet.java:74)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.kablink.teaming.web.servlet.filter.LoginFilter.doFilter(LoginFilter.java:155)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.kablink.teaming.web.servlet.filter.DefaultCharacterEncodingFilter.doFilter(DefaultCharacterEncodingFilter.java:60)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)
at org.springframework.security.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
at org.springframework.security.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
at org.springframework.security.ui.SessionFixationProtectionFilter.doFilterHttp(SessionFixationProtectionFilter.java:67)
at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
at org.springframework.security.ui.ExceptionTranslationFilter.doFilterHttp(ExceptionTranslationFilter.java:101)
at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
at org.springframework.security.providers.anonymous.AnonymousProcessingFilter.doFilterHttp(AnonymousProcessingFilter.java:105)
at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
at org.springframework.security.wrapper.SecurityContextHolderAwareRequestFilter.doFilterHttp(SecurityContextHolderAwareRequestFilter.java:91)
at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
at org.springframework.security.ui.AbstractProcessingFilter.doFilterHttp(AbstractProcessingFilter.java:278)
at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
at org.springframework.security.ui.basicauth.BasicProcessingFilter.doFilterHttp(BasicProcessingFilter.java:174)
at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
at org.kablink.teaming.spring.security.LogoutFilter.doFilterHttp(LogoutFilter.java:73)
at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
at org.springframework.security.context.HttpSessionContextIntegrationFilter.doFilterHttp(HttpSessionContextIntegrationFilter.java:235)
at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
at org.springframework.security.util.FilterChainProxy.doFilter(FilterChainProxy.java:175)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.kablink.teaming.asmodule.servlet.filter.ResponseHeaderFilter.doFilter(ResponseHeaderFilter.java:127)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.kablink.teaming.tomcat.valve.ZoneContextValve.invoke(ZoneContextValve.java:69)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:647)
at org.apache.catalina.valves.RequestFilterValve.process(RequestFilterValve.java:316)
at org.apache.catalina.valves.RemoteAddrValve.invoke(RemoteAddrValve.java:81)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.NoSuchMethodError: net.mail.CustomEmailNotification: method <init>()V not found
at org.kablink.teaming.module.definition.notify.NotifyBuilderUtil.buildElements(NotifyBuilderUtil.java:203)
at org.kablink.teaming.module.definition.notify.NotifyBuilderUtil.buildElements(NotifyBuilderUtil.java:175)
at org.kablink.teaming.module.mail.impl.DefaultEmailFormatter.buildMessage(DefaultEmailFormatter.java:821)
at org.kablink.teaming.module.mail.MimeNotifyPreparator.prepare(MimeNotifyPreparator.java:334)
at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:352)
at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:344)
at org.kablink.teaming.module.mail.impl.MailModuleImpl.sendMail(MailModuleImpl.java:1139)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.kablink.teaming.module.interceptor.EventListenerManagerInterceptor.invoke(EventListenerManagerInterceptor.java:64)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.kablink.teaming.util.aopalliance.InvocationStatisticsInterceptor.invoke(InvocationStatisticsInterceptor.java:49)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at com.sun.proxy.$Proxy13.sendMail(Unknown Source)
at org.kablink.teaming.module.admin.impl.AbstractAdminModule.sendMail(AbstractAdminModule.java:1174)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.kablink.teaming.search.interceptor.IndexSynchronizationManagerInterceptor.invoke(IndexSynchronizationManagerInterceptor.java:67)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.kablink.teaming.module.interceptor.EventListenerManagerInterceptor.invoke(EventListenerManagerInterceptor.java:64)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.kablink.teaming.util.aopalliance.InvocationStatisticsInterceptor.invoke(InvocationStatisticsInterceptor.java:49)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at com.sun.proxy.$Proxy16.sendMail(Unknown Source)
at org.kablink.teaming.web.util.BinderHelper.sendMailOnEntryCreate(BinderHelper.java:3171)
at org.kablink.teaming.portlet.forum.ModifyEntryController.handleActionRequestAfterValidation(ModifyEntryController.java:202)
at org.kablink.teaming.web.portlet.SAbstractController.handleActionRequestInternal(SAbstractController.java:257)
at org.springframework.web.portlet.mvc.AbstractController.handleActionRequest(AbstractController.java:199)
at org.springframework.web.portlet.mvc.SimpleControllerHandlerAdapter.handleAction(SimpleControllerHandlerAdapter.java:64)
at org.springframework.web.portlet.DispatcherPortlet.doActionService(DispatcherPortlet.java:641)
... 70 more
I am not able to find a reason why this is happening. Can anybody can help me point out where I am going wrong?
I am using Apache Tomcat/6.0.35
JVM Version: 1.7.0_21-b11
(Answered in the comments. Converted to a community wiki answer. See Question with no answers, but issue solved in the comments (or extended in chat) )
The OP wrote:
The problem is fixed now. The error was due to SVN branching. In a separate branch, there is another java class EmailHelper.java within the same folder where CustomEmailNotification.java resides. So when I switched from that branch to my current one, I did not checkout that branch as I did not require the EmailHelper.java, hence the error. Just created a separate folder containing just CustomEmailNotification.java, and the error is gone. Thanks to all for taking their time in looking into this

Nullpointer exception when invoking EJB

The following code seems to throw a NullPointerException at the QuestionRepository class, but I don't managed to fix it. I don't know if I have done anything wrong with the context dependency injection?
Entity
#Entity
#NamedQueries({
#NamedQuery(name=Question.ALL, query="SELECT q FROM Question q")
})
public class Question implements Serializable {
private static final long serialVersionUID = 2402027045394206281L;
public static final String ALL = "Question.all";
Repository
#Named
public class QuestionRepository {
#PersistenceContext(unitName="SertifikatPU")
private EntityManager entityManager;
public List<Question> all() {
TypedQuery<Question> query = entityManager.createNamedQuery(Question.ALL, Question.class);
return query.getResultList();
}
}
EJB
#Local(QuestionLocal.class)
#Stateless
public class QuestionServiceBean implements QuestionLocal {
#Inject
private QuestionRepository questionRepository;
#Override
public List<Question> findAllQuestions() {
return questionRepository.all();
}
}
Backing bean
#ManagedBean
#ViewScoped
public class QuestionIndexBean implements Serializable {
private static final long serialVersionUID = 4228471944163051591L;
#Inject
private QuestionLocal questionBean;
private List<Question> questions;
public void init() {
setQuestions(questionBean.findAllQuestions());
}
public List<Question> getQuestions() {
return questions;
}
public void setQuestions(List<Question> questions) {
this.questions = questions;
}
}
Exception:
WARNING: A system exception occurred during an invocation on EJB QuestionServiceBean method public java.util.List com.mycompany.application.QuestionServiceBean.findAllQuestions()
javax.ejb.EJBException
at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:5193)
at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:5091)
at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4879)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2039)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1990)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:222)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88)
at $Proxy208.findAllQuestions(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.jboss.weld.util.reflection.SecureReflections$13.work(SecureReflections.java:305)
at org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:54)
at org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInvocation(SecureReflectionAccess.java:163)
at org.jboss.weld.util.reflection.SecureReflections.invoke(SecureReflections.java:299)
at org.jboss.weld.bean.proxy.EnterpriseBeanProxyMethodHandler.invoke(EnterpriseBeanProxyMethodHandler.java:125)
at org.jboss.weld.bean.proxy.EnterpriseTargetBeanInstance.invoke(EnterpriseTargetBeanInstance.java:62)
at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:125)
at com.mycompany.application.org$jboss$weld$bean-SertifikatEJB_jar-SessionBean-QuestionServiceBean_$$_WeldProxy.findAllQuestions(org$jboss$weld$bean-SertifikatEJB_jar-SessionBean-QuestionServiceBean_$$_WeldProxy.java)
at com.mycompany.web.QuestionIndexBean.init(QuestionIndexBean.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.el.parser.AstValue.invoke(AstValue.java:234)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)
at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:43)
at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:56)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at com.sun.faces.facelets.tag.jsf.core.DeclarativeSystemEventListener.processEvent(EventHandler.java:128)
at javax.faces.component.UIComponent$ComponentSystemEventListenerAdapter.processEvent(UIComponent.java:2508)
at javax.faces.event.SystemEvent.processListener(SystemEvent.java:106)
at com.sun.faces.application.ApplicationImpl.processListeners(ApplicationImpl.java:2129)
at com.sun.faces.application.ApplicationImpl.invokeComponentListenersFor(ApplicationImpl.java:2077)
at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:286)
at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:244)
at javax.faces.application.ApplicationWrapper.publishEvent(ApplicationWrapper.java:670)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:108)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.NullPointerException
at com.mycompany.repository.QuestionRepository.all(QuestionRepository.java:17)
at com.mycompany.application.QuestionServiceBean.findAllQuestions(QuestionServiceBean.java:21)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1052)
at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1124)
at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:5366)
at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:619)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:571)
at org.jboss.weld.ejb.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:46)
at sun.reflect.GeneratedMethodAccessor109.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:861)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:571)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doAround(SystemInterceptorProxy.java:162)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:144)
at sun.reflect.GeneratedMethodAccessor108.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:861)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:370)
at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5338)
at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5326)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:214)
... 61 more
Persistence XML
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="SertifikatPU">
<jta-data-source>jdbc/sertifikat</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
</persistence-unit>
</persistence>
Project structure:
Try to merge the projects in one. Maybe there is a bug in the frameworks when more than one project is used.
Your problem is located at your class QuestionRepository.
If I've read it right, this is a simple class, not a server managed class. What does it mean? It means that due that this cause, this piece of code
#PersistenceContext(unitName="SertifikatPU")
private EntityManager entityManager;
does nothing because the class is instanced by you, nor by the server, so the persistence context is unknown from the point of view of the class. The consequence is that at this other piece of code
public List<Question> all() {
TypedQuery<Question> query = entityManager.createNamedQuery(Question.ALL, Question.class);
return query.getResultList();
}
entityManager will be null so it will cause the null pointer exception.
The solution? Declare QuestionRepository as an EJB too, as example . This way the Persistence Context injection will be automatically done by the server and the entity manager will be initialized at the moment you try to execute the query

Categories

Resources