public Integer insertEncashLeaveRecordForEmp(
final EncashedLeaveRecord encashRecord) {
KeyHolder keyHolder = new GeneratedKeyHolder();
Integer update = null;
final String sql = "INSERT INTO lms_dat_encashcarryoverleaves(EncashCarry_NumOfLeaves,"
+ "fk_EncashCarry_empId,EncashCarry_AppliedDate, "
+ "fk_EncashCarry_StatusId, fk_EncashCarry_LeaveTypeID, "
+ "fk_EncashCarry_UpdatedById,EncashCarry_UpdatedOn) "
+ " values (?,?,?,?,?,?,now())";
/*
try {
update = misJdbcTemplate
.update(sql, encashRecord.getNumberOfLeaves(), encashRecord
.getEmployeeId(),
new Date(new java.util.Date().getTime()),
encashRecord.getLeaveStatusId(), encashRecord
.getLeaveTypeId(), encashRecord
.getEmployeeId());
} catch (Exception e) {
return 0;
}*/
try {
jdbcTemplate.update(new PreparedStatementCreator() {
public PreparedStatement createPreparedStatement(
Connection connection) throws SQLException {
PreparedStatement ps = connection.prepareStatement(sql,
new String[] { "pk_EncashCarry_ECId" });
ps.setFloat(0, encashRecord.getNumberOfLeaves());
ps.setInt(2, encashRecord.getEmployeeId());
ps.setDate(3, new java.sql.Date(System.currentTimeMillis()));
ps.setInt(4,encashRecord.getLeaveStatusId());
ps.setInt(5,encashRecord.getLeaveTypeId());
ps.setInt(6,encashRecord
.getEmployeeId());
return ps;
}
}, keyHolder);
} catch (Exception e) {
e.printStackTrace();
}
return keyHolder.getKey().intValue();
}
I am trying to save above values using spring jdbc template but getting this exception.
Exception
org.springframework.dao.TransientDataAccessResourceException: PreparedStatementCallback; SQL []; Parameter index out of range (0 < 1 ).; nested exception is java.sql.SQLException: Parameter index out of range (0 < 1 ).
at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:107)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:602)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:842)
at com.thbs.intranet.rest.dao.misdatabase.impl.EncashedLeaveRecordsDaoImpl.insertEncashLeaveRecordForEmp(EncashedLeaveRecordsDaoImpl.java:244)
at com.thbs.intranet.rest.service.impl.EmployeeLeaveServiceImpl.applyEncashLeaveByEmp(EmployeeLeaveServiceImpl.java:1218)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
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.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at com.sun.proxy.$Proxy33.applyEncashLeaveByEmp(Unknown Source)
at com.thbs.intranet.rest.resource.EmployeeResource.applyEncashLeaveByEmp(EmployeeResource.java:934)
at com.thbs.intranet.rest.resource.EmployeeResource$$FastClassByCGLIB$$f9a9f6b5.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:688)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:50)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.aspectj.AspectJAfterThrowingAdvice.invoke(AspectJAfterThrowingAdvice.java:55)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:50)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:621)
at com.thbs.intranet.rest.resource.EmployeeResource$$EnhancerByCGLIB$$1d5273d3.applyEncashLeaveByEmp(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:187)
at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:70)
at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:279)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:136)
at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:86)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:136)
at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:74)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1357)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1289)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1239)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1229)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:420)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:497)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:684)
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.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:368)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:97)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:100)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:78)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:35)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:177)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:169)
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.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:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
Caused by: java.sql.SQLException: Parameter index out of range (0 < 1 ).
The index parameters in PreparedStatements start on 1, not 0. If you check oracle documentation:
https://docs.oracle.com/javase/7/docs/api/java/sql/PreparedStatement.html
In any method description:
setFloat(int parameterIndex, double x)
Parameters:
parameterIndex - the first parameter is 1, the second is 2, ...
x - the parameter value
So try to change:
From
ps.setFloat(0, encashRecord.getNumberOfLeaves());
To
ps.setFloat(1, encashRecord.getNumberOfLeaves());
Related
Trying to remove an Address object from the session I get this exception org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session.
The following is the calling source code :
//The relation between a User and an Address is Ont-To-One with no cascade at any of the joining columns (Address#user and User#address)
Address address = user.getAddress();
if(address!=null){
usr.setAddress(null);
//I have tried to merge before/after unbinding the object from the session, neither of both worked
//addressDao.merge(addressByAddress);
addressDao.unbindObjectFromSession(addressByAddress);
addressDao.remove(addressByAddress);
}
AddressDaoImpl.java
public class AddressDaoImpl extends GenericDaoImpl<Address> implements AddressDao {
private static org.apache.log4j.Logger log = Logger.getLogger(AddressDaoImpl.class);
public AddressDaoImpl() {
super(Address.class);
}
//omitted source code
}
GenericDaoImpl.java
public class GenericDaoImpl<T extends IdInterface> extends HibernateDaoSupport implements GenericDao<T> {
private static final Logger LOG = LoggerFactory.getLogger(GenericDaoImpl.class);
private final Class<T> type;
public GenericDaoImpl(final Class<T> type) {
this.type = type;
}
#Override
public boolean remove(final T removeObject) {
getHibernateTemplate().delete(removeObject);
LOG.trace("An entity of type \"{}\" has been deleted from db. ID: {}", type.getSimpleName(), removeObject.getId());
return true;
}
#Override
public void unbindObjectFromSession(final Object unbindObject) {
getSession().evict(unbindObject);
getSession().flush();
LOG.trace("An entity of type \"{}\" has been unbound from session. ID: {}", type.getSimpleName(), unbindObject.getClass().getSimpleName());
}
#Override
public void merge(final Object obj) {
log.debug("merge("+address.getId()+")");
this.getHibernateTemplate().merge(obj);
}
//omitted source code
}
The exception stacktrace :
SCHWERWIEGEND: org.springframework.orm.hibernate3.HibernateSystemException: a different object with the same identifier value was already associated with the session: [de.fruuts.db.entities.Address#15701]; nested exception is org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [de.fruuts.db.entities.Address#15701]
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:676)
at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:424)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
at org.springframework.orm.hibernate3.HibernateTemplate.delete(HibernateTemplate.java:846)
at org.springframework.orm.hibernate3.HibernateTemplate.delete(HibernateTemplate.java:842)
at de.fruuts.business.dao.hibernateimpl.GenericDaoImpl.remove(GenericDaoImpl.java:79)
at sun.reflect.GeneratedMethodAccessor399.invoke(Unknown Source)
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:307)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
at org.springframework.aop.aspectj.AspectJAfterAdvice.invoke(AspectJAfterAdvice.java:42)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:50)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at com.sun.proxy.$Proxy68.remove(Unknown Source)
at de.fruuts.business.service.impl.UserServiceImpl.removeUsrFruutsPersonalData(UserServiceImpl.java:1731)
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:307)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
at org.springframework.aop.aspectj.AspectJAfterAdvice.invoke(AspectJAfterAdvice.java:42)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:50)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at com.sun.proxy.$Proxy80.removeUsrFruutsPersonalData(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.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at com.sun.proxy.$Proxy81.removeUsrFruutsPersonalData(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.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
at org.springframework.aop.aspectj.AspectJAfterAdvice.invoke(AspectJAfterAdvice.java:42)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:50)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at com.sun.proxy.$Proxy81.removeUsrFruutsPersonalData(Unknown Source)
at de.fruuts.web.beans.impl.AdminBeanImpl.removeUsrPersonalData(AdminBeanImpl.java:658)
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:307)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
at org.springframework.aop.aspectj.AspectJAfterAdvice.invoke(AspectJAfterAdvice.java:42)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:50)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at com.sun.proxy.$Proxy150.removeUsrPersonalData(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.apache.el.parser.AstValue.invoke(AstValue.java:191)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:99)
at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:771)
at javax.faces.component.UICommand.broadcast(UICommand.java:372)
at com.icesoft.faces.component.panelseries.UISeries$RowEvent.broadcast(UISeries.java:610)
at com.icesoft.faces.component.panelseries.UISeries.broadcast(UISeries.java:275)
at javax.faces.component.UIData.broadcast(UIData.java:938)
at com.icesoft.faces.component.panelseries.UISeries.broadcast(UISeries.java:270)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:475)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:756)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:82)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at com.icesoft.faces.webapp.http.core.JsfLifecycleExecutor.apply(JsfLifecycleExecutor.java:18)
at com.icesoft.faces.webapp.http.core.ReceiveSendUpdates.renderCycle(ReceiveSendUpdates.java:122)
at com.icesoft.faces.webapp.http.core.ReceiveSendUpdates.service(ReceiveSendUpdates.java:73)
at com.icesoft.faces.webapp.http.core.RequestVerifier.service(RequestVerifier.java:28)
at com.icesoft.faces.webapp.http.common.standard.PathDispatcherServer.service(PathDispatcherServer.java:24)
at com.icesoft.faces.webapp.http.servlet.MainSessionBoundServlet.service(MainSessionBoundServlet.java:160)
at com.icesoft.faces.webapp.http.servlet.SessionDispatcher$1.service(SessionDispatcher.java:42)
at com.icesoft.faces.webapp.http.servlet.ThreadBlockingAdaptingServlet.service(ThreadBlockingAdaptingServlet.java:19)
at com.icesoft.faces.webapp.http.servlet.EnvironmentAdaptingServlet.service(EnvironmentAdaptingServlet.java:63)
at com.icesoft.faces.webapp.http.servlet.SessionDispatcher.service(SessionDispatcher.java:62)
at com.icesoft.faces.webapp.http.servlet.SessionVerifier.service(SessionVerifier.java:22)
at com.icesoft.faces.webapp.http.servlet.PathDispatcher.service(PathDispatcher.java:23)
at com.icesoft.faces.webapp.http.servlet.MainServlet.service(MainServlet.java:153)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
at com.icesoft.faces.webapp.xmlhttp.BlockingServlet.service(BlockingServlet.java:56)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:71)
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.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.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:277)
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.logout.LogoutFilter.doFilterHttp(LogoutFilter.java:89)
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:236)
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.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
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 de.fruuts.web.filter.Log4jSessionFilter.doFilter(Log4jSessionFilter.java:49)
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:103)
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:861)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:695)
Caused by: org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [de.fruuts.db.entities.Address#15701]
at org.hibernate.engine.StatefulPersistenceContext.checkUniqueness(StatefulPersistenceContext.java:556)
at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:88)
at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:49)
at org.hibernate.impl.SessionImpl.fireDelete(SessionImpl.java:766)
at org.hibernate.impl.SessionImpl.delete(SessionImpl.java:744)
at org.springframework.orm.hibernate3.HibernateTemplate$25.doInHibernate(HibernateTemplate.java:852) at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:419)
... 164 more
What you're trying to accomplish should work just like this:
// Start a spring transaction that wraps the operation
#Transactional
public void removeAddressById(Long addressId) {
// I'm just locating the address from the database based on some provided id.
final Address address = addressDao.findById( addressId );
// break the association between the associated User and Address.
address.getUser().setAddress( null );
address.setUser( null );
// Update the user and remove the address
// If address owns the one-to-one association, then the merge is unnecessary
getHibernateTemplate().merge( user );
getHibernateTemplate().delete( address );
}
Since you are trying to delete/remove an entity, the object will be evicted from the persistence context by the persistence provider automatically.
I have for to login my site
<form method="post" action="login">
<input type="text" placeholder="Email" name="email">
<input type="password" placeholder="Password" name="password">
<button type="submit">Login</button>
</form>
in controller I have
#RequestMapping(value="/login",method=RequestMethod.POST)
public String loginUser(#RequestParam("email") String email,
#RequestParam("password") String password,Model model,HttpSession session){
User persistedUser = userService.getUserByEmail(email);
if(persistedUser!=null && persistedUser.getPassword().equals(password)){
session.setAttribute("user", persistedUser);
return "home";
}else{
model.addAttribute("error", "Incorrect username or password, Please try again!");
return "login";
}
}
and in UserService I getUserByEmail() as
public User getUserByEmail(String email) {
return (User) em.createQuery("SELECT * FROM User u WHERE u.email = :email").setParameter(email, "Not Found");
}
when i try to log in I get
org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: * near line 1, column 8 [SELECT * FROM com.rhcloud.giveme.entity.User u WHERE u.email = :email]
at org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:91)
at org.hibernate.hql.internal.ast.ErrorCounter.throwQueryException(ErrorCounter.java:109)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:304)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:203)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:158)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:126)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:88)
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:190)
at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:301)
at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:236)
at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1800)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:344)
at $Proxy76.createQuery(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:291)
at $Proxy70.createQuery(Unknown Source)
at com.rhcloud.giveme.service.UserService.getUserByEmail(UserService.java:33)
at com.rhcloud.giveme.service.UserService$$FastClassBySpringCGLIB$$11c5f2a8.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:649)
at com.rhcloud.giveme.service.UserService$$EnhancerBySpringCGLIB$$79be29e2.getUserByEmail(<generated>)
at com.rhcloud.giveme.controller.LoginController.loginUser(LoginController.java:31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:776)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:705)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:868)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
How can I write correct query for getUserByEmail(), so that I can get rid of this exception.
You have to omit the SELECT * part, it's implicit:
return (User) em.createQuery("FROM User u WHERE u.email = :email").setParameter(email, "Not Found");
The code is this:
import static jodd.jtx.JtxPropagationBehavior.PROPAGATION_SUPPORTS;
#PetiteBean
public class FooService {
#PetiteInject
AppDao appDao;
#Transaction(propagation = PROPAGATION_SUPPORTS, readOnly = false)
public void storeUser(User user) {
appDao.store(user);
}
#Transaction(propagation = PROPAGATION_SUPPORTS)
public User findUserById(long id) {
return appDao.findById(User.class, Long.valueOf(id));
}
#Transaction(propagation = PROPAGATION_SUPPORTS)
public void updateDetails(User user) {
appDao.updateUserName(user); //line no 18
appDao.updateAddress(user); //line no 19
}
}
if line 18 is executed successfully and there is exception on line 19 execution then changes due to line 18 should be rollback. how can I do that.?
Changed ::
#Transaction
public void updateDetails(User user) throws DatabaseException {
try {
appDao.updateUserName(user); //line no 18
appDao.updateAddress(user); //line no 19
} catch (DatabaseException e) {
e.printStackTrace();
System.out.println("Throwing Exception" );
throw new DatabaseException(e.getMessage());
}
}
Actual Code ::
#Transaction
public void updateCategory(CategoryData categoryData) throws DatabaseException {
try {
Category category = DataConvertionUtil.prepareCategory(categoryData);
userDao.updateCategory(category);
userDao.updateCategory1(category);
} catch (DatabaseException e) {
e.printStackTrace();
System.out.println("Throwing Exception" );
throw new DatabaseException(e.getMessage());
}
}
Appcore.java
public class AppCore {
public void start() {
// AppUtil.resolveDirs();
initLogger();
initProxetta();
initPetite();
initDb();
// init everything else
}
private void initLogger() {
LoggerFactory.setLoggerFactory(new SimpleLoggerFactory(Level.DEBUG));
}
public void stop() {
// close everything
petite.shutdown();
}
JtxTransactionManager jtxManager;
ConnectionProvider connectionProvider;
protected PetiteContainer petite;
protected boolean isWebApplication;
ProxyProxetta proxetta;
void initPetite() {
petite = new ProxettaAwarePetiteContainer(proxetta);
if (isWebApplication == false) {
petite.registerScope(SessionScope.class, new ProtoScope());
}
AutomagicPetiteConfigurator pcfg = new AutomagicPetiteConfigurator();
pcfg.setIncludedEntries(this.getClass().getPackage().getName() + ".*");
pcfg.configure(petite);
// load parameters
Props appProps = new Props();
appProps.loadSystemProperties("sys");
appProps.loadEnvironment("env");
PropsUtil.loadFromClasspath(appProps, "/app*.prop*");
petite.defineParameters(appProps);
// add appCore to Petite (and resolve parameters)
petite.addBean("app", this);
}
void initDb() {
DbOomManager dbOomManager = DbOomManager.getInstance();
// manual configuration (before entities registration)
TableNamingStrategy tns = new TableNamingStrategy();
tns.setPrefix("");
tns.setUppercase(false);
dbOomManager.setTableNames(tns);
ColumnNamingStrategy cns = new ColumnNamingStrategy();
cns.setUppercase(false);
dbOomManager.setColumnNames(cns);
// automatic configuration
AutomagicDbOomConfigurator dbcfg = new AutomagicDbOomConfigurator();
dbcfg.setIncludedEntries(this.getClass().getPackage().getName() + ".*");
dbcfg.configure(dbOomManager);
petite.registerPetiteBean(CoreConnectionPool.class, "dbpool", null, null, false);
connectionProvider = (ConnectionProvider) petite.getBean("dbpool");
connectionProvider.init();
// transactions
jtxManager = new DbJtxTransactionManager(connectionProvider);
jtxManager.setValidateExistingTransaction(true);
AnnotationTxAdviceSupport.manager = new AnnotationTxAdviceManager(jtxManager, "$class");
DbSessionProvider sessionProvider = new DbJtxSessionProvider(jtxManager);
// global settings
DbManager dbManager = DbManager.getInstance();
// dbManager.setDebug(true); for loading each time query
dbManager.setDebug(true);
dbManager.setConnectionProvider(connectionProvider);
dbManager.setSessionProvider(sessionProvider);
petite.addBean("dbManager", dbManager);
}
void initProxetta() {
#SuppressWarnings("unchecked")
ProxyAspect txServiceProxy = new ProxyAspect(AnnotationTxAdvice.class, new MethodAnnotationPointcut(Transaction.class) {
#Override
public boolean apply(MethodInfo mi) {
return isPublic(mi) && isTopLevelMethod(mi) && matchClassName(mi, "*Service") && super.apply(mi);
}
});
proxetta = ProxyProxetta.withAspects(txServiceProxy);
proxetta.setClassLoader(this.getClass().getClassLoader());
}
public PetiteContainer getPetite() {
return petite;
}
void stopDb() {
jtxManager.close();
connectionProvider.close();
}
}
Debug Log::
-----> /category.update.html [com.kirtan.jodd.action.category.ManageCategoryAction#update]
22307 [INFO] c.k.j.a.c.ManageCategoryAction.update:151 - ManageCategoryAction.update()CategoryData [categoryId=5, name=SOA2, parentCategoryName=null, parentCategoryId=1, createdDate=null]
22307 [DEBUG] j.j.JtxTransactionManager.requestTransaction:250 - Requesting TX jtx{Supports,readonly,Default,-1}
22307 [DEBUG] j.j.JtxTransaction.<init>:72 - New JTX {status:No transaction, mode:jtx{Supports,readonly,Default,-1}}
22307 [INFO] c.k.j.d.QueryBuilder.generateSql:39 - SQL String :: update TBLMCATEGORY set parentCategoryId = 1 , name = 'SOA2' where ( categoryId = 5 ) ;
22307 [INFO] c.k.j.d.QueryBuilder.generateSql:42 - Time Taken for Generating SQL String :: 0
22307 [DEBUG] j.d.j.DbJtxSessionProvider.getDbSession:33 - Requesting db TX manager session
22307 [DEBUG] j.d.DbSession.<init>:45 - Creating new db session
22307 [DEBUG] j.d.p.CoreConnectionPool.getConnection:224 - Returning valid pooled connection
22307 [DEBUG] j.d.DbQueryBase.executeUpdate:660 - Executing update: update TBLMCATEGORY set parentCategoryId = 1 , name = 'SOA2' where ( categoryId = 5 ) ;
22307 [DEBUG] j.d.DbQueryBase.executeUpdate:685 - execution time: 0ms
22307 [INFO] c.k.j.d.QueryBuilder.generateSql:39 - SQL String :: update TBLMCATEGORY set categoryId = 1 , parentCategoryId = 1 , name = 'SOA2' where ( categoryId = 5 ) ;
22307 [INFO] c.k.j.d.QueryBuilder.generateSql:42 - Time Taken for Generating SQL String :: 0
22307 [DEBUG] j.d.j.DbJtxSessionProvider.getDbSession:33 - Requesting db TX manager session
22307 [DEBUG] j.d.DbQueryBase.executeUpdate:660 - Executing update: update TBLMCATEGORY set categoryId = 1 , parentCategoryId = 1 , name = 'SOA2' where ( categoryId = 5 ) ;
jodd.db.DbSqlException: Query execution failed
Query: update TBLMCATEGORY set categoryId = 1 , parentCategoryId = 1 , name = 'SOA2' where ( categoryId = 5 ) ; ; <--- com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '1' for key 'PRIMARY'
at jodd.db.DbQueryBase.executeUpdate(DbQueryBase.java:677)
at jodd.db.DbQueryBase.executeUpdate(DbQueryBase.java:647)
at jodd.db.DbQuery.executeUpdate(DbQuery.java:49)
at com.kirtan.jodd.dao.AppDao.executeUpdate(AppDao.java:85)
at com.kirtan.jodd.dao.UserDao.updateCategory1(UserDao.java:67)
at com.kirtan.jodd.service.UserService.updateCategory(UserService.java:131)
at com.kirtan.jodd.service.UserService$$Proxetta.updateCategory$0(Unknown Source)
at com.kirtan.jodd.service.UserService$$Proxetta.updateCategory(Unknown Source)
at com.kirtan.jodd.action.category.ManageCategoryAction.update(ManageCategoryAction.java:152)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at jodd.madvoc.ActionRequest.invokeActionMethod(ActionRequest.java:332)
at jodd.madvoc.ActionRequest$2.invoke(ActionRequest.java:218)
at jodd.madvoc.ActionRequest.invoke(ActionRequest.java:322)
at jodd.madvoc.interceptor.EchoInterceptor.intercept(EchoInterceptor.java:43)
at jodd.madvoc.interceptor.BaseActionInterceptor.invoke(BaseActionInterceptor.java:15)
at jodd.madvoc.ActionRequest.invoke(ActionRequest.java:322)
at jodd.madvoc.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:48)
at jodd.madvoc.interceptor.BaseActionInterceptor.invoke(BaseActionInterceptor.java:15)
at jodd.madvoc.ActionRequest.invoke(ActionRequest.java:322)
at jodd.joy.i18n.I18nInterceptor.intercept(I18nInterceptor.java:22)
at jodd.madvoc.interceptor.BaseActionInterceptor.invoke(BaseActionInterceptor.java:15)
at jodd.madvoc.ActionRequest.invoke(ActionRequest.java:322)
at jodd.madvoc.ActionRequest$1.invoke(ActionRequest.java:199)
at jodd.madvoc.ActionRequest.invoke(ActionRequest.java:322)
at com.kirtan.jodd.filter.SessionFilter.filter(SessionFilter.java:35)
at jodd.madvoc.filter.BaseActionFilter.invoke(BaseActionFilter.java:15)
at jodd.madvoc.ActionRequest.invoke(ActionRequest.java:322)
at jodd.madvoc.component.MadvocController.invoke(MadvocController.java:141)
at jodd.madvoc.MadvocServletFilter.doFilter(MadvocServletFilter.java:88)
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:103)
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:861)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:620)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '1' for key 'PRIMARY'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1040)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4096)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4028)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2490)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2651)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2728)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1811)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1725)
at jodd.db.DbQueryBase.executeUpdate(DbQueryBase.java:671)
... 43 more
---[cause]------------------------------------------------------------------------
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '1' for key 'PRIMARY'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1040)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4096)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4028)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2490)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2651)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2728)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1811)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1725)
at jodd.db.DbQueryBase.executeUpdate(DbQueryBase.java:671)
at jodd.db.DbQueryBase.executeUpdate(DbQueryBase.java:647)
at jodd.db.DbQuery.executeUpdate(DbQuery.java:49)
at com.kirtan.jodd.dao.AppDao.executeUpdate(AppDao.java:85)
at com.kirtan.jodd.dao.UserDao.updateCategory1(UserDao.java:67)
at com.kirtan.jodd.service.UserService.updateCategory(UserService.java:131)
at com.kirtan.jodd.service.UserService$$Proxetta.updateCategory$0(Unknown Source)
at com.kirtan.jodd.service.UserService$$Proxetta.updateCategory(Unknown Source)
at com.kirtan.jodd.action.category.ManageCategoryAction.update(ManageCategoryAction.java:152)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at jodd.madvoc.ActionRequest.invokeActionMethod(ActionRequest.java:332)
at jodd.madvoc.ActionRequest$2.invoke(ActionRequest.java:218)
at jodd.madvoc.ActionRequest.invoke(ActionRequest.java:322)
at jodd.madvoc.interceptor.EchoInterceptor.intercept(EchoInterceptor.java:43)
at jodd.madvoc.interceptor.BaseActionInterceptor.invoke(BaseActionInterceptor.java:15)
at jodd.madvoc.ActionRequest.invoke(ActionRequest.java:322)
at jodd.madvoc.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:48)
at jodd.madvoc.interceptor.BaseActionInterceptor.invoke(BaseActionInterceptor.java:15)
at jodd.madvoc.ActionRequest.invoke(ActionRequest.java:322)
at jodd.joy.i18n.I18nInterceptor.intercept(I18nInterceptor.java:22)
at jodd.madvoc.interceptor.BaseActionInterceptor.invoke(BaseActionInterceptor.java:15)
at jodd.madvoc.ActionRequest.invoke(ActionRequest.java:322)
at jodd.madvoc.ActionRequest$1.invoke(ActionRequest.java:199)
at jodd.madvoc.ActionRequest.invoke(ActionRequest.java:322)
at com.kirtan.jodd.filter.SessionFilter.filter(SessionFilter.java:35)
at jodd.madvoc.filter.BaseActionFilter.invoke(BaseActionFilter.java:15)
at jodd.madvoc.ActionRequest.invoke(ActionRequest.java:322)
at jodd.madvoc.component.MadvocController.invoke(MadvocController.java:141)
at jodd.madvoc.MadvocServletFilter.doFilter(MadvocServletFilter.java:88)
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:103)
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:861)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:620)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
com.kirtan.jodd.exception.DatabaseException: Query execution failed
Query: update TBLMCATEGORY set categoryId = 1 , parentCategoryId = 1 , name = 'SOA2' where ( categoryId = 5 ) ; ; <--- com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '1' for key 'PRIMARY'
at com.kirtan.jodd.dao.AppDao.executeUpdate(AppDao.java:88)
at com.kirtan.jodd.dao.UserDao.updateCategory1(UserDao.java:67)
at com.kirtan.jodd.service.UserService.updateCategory(UserService.java:131)
at com.kirtan.jodd.service.UserService$$Proxetta.updateCategory$0(Unknown Source)
at com.kirtan.jodd.service.UserService$$Proxetta.updateCategory(Unknown Source)
at com.kirtan.jodd.action.category.ManageCategoryAction.update(ManageCategoryAction.java:152)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at jodd.madvoc.ActionRequest.invokeActionMethod(ActionRequest.java:332)
at jodd.madvoc.ActionRequest$2.invoke(ActionRequest.java:218)
at jodd.madvoc.ActionRequest.invoke(ActionRequest.java:322)
at jodd.madvoc.interceptor.EchoInterceptor.intercept(EchoInterceptor.java:43)
at jodd.madvoc.interceptor.BaseActionInterceptor.invoke(BaseActionInterceptor.java:15)
at jodd.madvoc.ActionRequest.invoke(ActionRequest.java:322)
at jodd.madvoc.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:48)
at jodd.madvoc.interceptor.BaseActionInterceptor.invoke(BaseActionInterceptor.java:15)
at jodd.madvoc.ActionRequest.invoke(ActionRequest.java:322)
at jodd.joy.i18n.I18nInterceptor.intercept(I18nInterceptor.java:22)
at jodd.madvoc.interceptor.BaseActionInterceptor.invoke(BaseActionInterceptor.java:15)
at jodd.madvoc.ActionRequest.invoke(ActionRequest.java:322)
at jodd.madvoc.ActionRequest$1.invoke(ActionRequest.java:199)
at jodd.madvoc.ActionRequest.invoke(ActionRequest.java:322)
at com.kirtan.jodd.filter.SessionFilter.filter(SessionFilter.java:35)
at jodd.madvoc.filter.BaseActionFilter.invoke(BaseActionFilter.java:15)
at jodd.madvoc.ActionRequest.invoke(ActionRequest.java:322)
at jodd.madvoc.component.MadvocController.invoke(MadvocController.java:141)
at jodd.madvoc.MadvocServletFilter.doFilter(MadvocServletFilter.java:88)
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:103)
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:861)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:620)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
Throwing Exception
22338 [DEBUG] j.j.w.LeanJtxWorker.markOrRollbackTransaction:92 - rollback tx
22338 [DEBUG] j.j.JtxTransaction.commitOrRollback:227 - Rollback JTX
22338 [DEBUG] j.d.DbSession.closeSession:67 - Closing db session
com.kirtan.jodd.exception.DatabaseException: Query execution failed
Query: update TBLMCATEGORY set categoryId = 1 , parentCategoryId = 1 , name = 'SOA2' where ( categoryId = 5 ) ; ; <--- com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '1' for key 'PRIMARY'
at com.kirtan.jodd.service.UserService.updateCategory(UserService.java:135)
at com.kirtan.jodd.service.UserService$$Proxetta.updateCategory$0(Unknown Source)
at com.kirtan.jodd.service.UserService$$Proxetta.updateCategory(Unknown Source)
at com.kirtan.jodd.action.category.ManageCategoryAction.update(ManageCategoryAction.java:152)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at jodd.madvoc.ActionRequest.invokeActionMethod(ActionRequest.java:332)
at jodd.madvoc.ActionRequest$2.invoke(ActionRequest.java:218)
at jodd.madvoc.ActionRequest.invoke(ActionRequest.java:322)
at jodd.madvoc.interceptor.EchoInterceptor.intercept(EchoInterceptor.java:43)
at jodd.madvoc.interceptor.BaseActionInterceptor.invoke(BaseActionInterceptor.java:15)
at jodd.madvoc.ActionRequest.invoke(ActionRequest.java:322)
at jodd.madvoc.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:48)
at jodd.madvoc.interceptor.BaseActionInterceptor.invoke(BaseActionInterceptor.java:15)
at jodd.madvoc.ActionRequest.invoke(ActionRequest.java:322)
at jodd.joy.i18n.I18nInterceptor.intercept(I18nInterceptor.java:22)
at jodd.madvoc.interceptor.BaseActionInterceptor.invoke(BaseActionInterceptor.java:15)
at jodd.madvoc.ActionRequest.invoke(ActionRequest.java:322)
at jodd.madvoc.ActionRequest$1.invoke(ActionRequest.java:199)
at jodd.madvoc.ActionRequest.invoke(ActionRequest.java:322)
at com.kirtan.jodd.filter.SessionFilter.filter(SessionFilter.java:35)
at jodd.madvoc.filter.BaseActionFilter.invoke(BaseActionFilter.java:15)
at jodd.madvoc.ActionRequest.invoke(ActionRequest.java:322)
at jodd.madvoc.component.MadvocController.invoke(MadvocController.java:141)
at jodd.madvoc.MadvocServletFilter.doFilter(MadvocServletFilter.java:88)
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:103)
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:861)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:620)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
<----- /category.update.html () in 31ms.
I am using mysql database. please help me into this...
Just throw the exception. When an exception is thrown, JTX proxy will catch it and mark transaction for rollback.
This behavior is defined in AnnotationTxAdvice class, although this is not something you should really care :)
EDIT
Quick overview tells me that the exception happens because you have duplicated entry for primary key:
Duplicate entry '1' for key 'PRIMARY'
which is expected behavior. Now, you asked this:
if line 18 is executed successfully and there is exception on line 19 execution then changes due to line 18 should be rollback. how can I do that?
This is what happens here:
#Transaction(propagation = PROPAGATION_SUPPORTS)
public void updateDetails(User user) {
appDao.updateUserName(user); //line no 18
appDao.updateAddress(user); //line no 19
}
If you use PROPAGATION_SUPPORTS then if no transaction is started, the code will run in non-transactional context. Which means, if line #19 throws exception, line #18 will NOT rollback (assuming transaction is not started before).
If you want both line 18 and 19 to be in one transaction, you should change the propagation to default (i.e. PROPAGATION_REQUIRED), that will create new transaction if not already started. With only that change, if line #19 throws exception, line #18 will rollback as well.
So just change the propagation :)
I am inserting a new row into a table with Spring JDBCTemplate. The jdbcTemplate.update() throws the following exception:
PreparedStatementCallback; uncategorized SQLException for SQL []; SQL state [99999]; error code [17090]; operation not allowed
But the row is inserted into the db anyway.
Here's the code:
final StringBuilder widgetInsert = new StringBuilder();
widgetInsert.append("INSERT INTO WIDGET (ID, KEY, DEPT_NUM, TYPE, CREATED_BY_ID, CREATED_DATE) ");
widgetInsert.append("VALUES (WIDGET_SEQ.NEXTVAL, ?, ?, ?, ?, ?) ");
Long widgetId;
try {
KeyHolder kh = new GeneratedKeyHolder();
jdbcTemplate.update(
new PreparedStatementCreator() {
#Override
public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
PreparedStatement ps = con.prepareStatement(widgetInsert.toString());
ps.setLong(1, key);
ps.setLong(2, deptNumber);
ps.setString(3, widgetType);
ps.setLong(4, creatorId);
ps.setLong(5, System.currentTimeMillis());
return ps;
}
}, kh);
widgetId = kh.getKey().longValue();
} catch (Exception e) {
// THIS EXCEPTION IS THROWN
throw new WidgetException("Problem inserting widget for key=" + key, e);
}
EDIT:
Running Spring JDBC 3.2.4.RELEASE
Full exception:
[21] 15/02/02 15:04:59.537 In StandardWrapperValve.invoke(): [127] org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException for SQL []; SQL state [99999]; error code [17090]; operation not allowed; nested exception is java.sql.SQLException: operation not allowed
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:83)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:605)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:849)
at org.acme.widget.service.WidgetServiceImpl.createWidget(WidgetServiceImpl.java:68)
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:606)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at com.sun.proxy.$Proxy21.getOrCreatePersonalOwner(Unknown Source)
at org.acme.service.BigServiceImpl.addStuff(BigServiceImpl.java:574)
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:606)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at com.sun.proxy.$Proxy22.addStuff(Unknown Source)
at org.acme.endpoint.BigRs.addStuff(BigRs.java:262)
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:606)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:440)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:428)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.acme.stack.auth.spring.AuthRequestParameterCleanupFilter.doFilter(AuthRequestParameterCleanupFilter.java:45)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.acme.stack.auth.spring.AuthContextSpringFilter.doFilter(AuthContextSpringFilter.java:90)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication.preauth.AbstractPreAuthenticatedProcessingFilter.doFilter(AbstractPreAuthenticatedProcessingFilter.java:94)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:343)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:260)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.acme.stack.web.servlet.filter.SessionlessFilter.doFilter(SessionlessFilter.java:30)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
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:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:203)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:683)
at org.acme.stack.tomcat.auth.AuthHostValve.invoke(AuthHostValve.java:145)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.sql.SQLException: operation not allowed
at oracle.jdbc.driver.OracleStatement.getGeneratedKeys(OracleStatement.java:5219)
at oracle.jdbc.driver.OracleStatementWrapper.getGeneratedKeys(OracleStatementWrapper.java:366)
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:606)
at org.apache.tomcat.jdbc.pool.interceptor.AbstractQueryReport$StatementProxy.invoke(AbstractQueryReport.java:235)
at com.sun.proxy.$Proxy89.getGeneratedKeys(Unknown Source)
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:606)
at org.apache.tomcat.jdbc.pool.interceptor.AbstractQueryReport$StatementProxy.invoke(AbstractQueryReport.java:235)
at com.sun.proxy.$Proxy89.getGeneratedKeys(Unknown Source)
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:606)
at org.apache.tomcat.jdbc.pool.interceptor.StatementDecoratorInterceptor$StatementProxy.invoke(StatementDecoratorInterceptor.java:252)
at com.sun.proxy.$Proxy89.getGeneratedKeys(Unknown Source)
at org.springframework.jdbc.core.JdbcTemplate$3.doInPreparedStatement(JdbcTemplate.java:854)
at org.springframework.jdbc.core.JdbcTemplate$3.doInPreparedStatement(JdbcTemplate.java:849)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:589)
... 96 more
I have faced the same problem when using org.springframework.jdbc.object.BatchSqlUpdate
in my code:
BatchSqlUpdate batchSqlUpdate = new BatchSqlUpdate(dataSource, getSqlString(), getSqlTypes(), 1);
KeyHolder keyHolder = new GeneratedKeyHolder();
long result;
int row = batchSqlUpdate.update(getObjParameters(tmpObj), keyHolder);
if (row > 0)
result = keyHolder.getKey().longValue();
It caused this error:
SQL state [99999]; error code [17090]; operation not allowed; nested exception is java.sql.SQLException: operation not allowed
I added these 2 lines before executing the update operation and the problem has been resolved:
batchSqlUpdate.setGeneratedKeysColumnNames(new String[]{"id"});
batchSqlUpdate.setReturnGeneratedKeys(true);
OK, this is solved for me. It may be an Oracle requirement - I don't know that for sure since I've not been able to run chenrui's test code on H2. Apparently the PreparedStatement requires the sequenced column(s) to be explicitly declared. So for my primary key column generated off the sequence I declare as follows:
final String generatedColumns[] = { "ID" };
I then pass the array into my prepareStatement() call inside the createPreparedStatement() method of the PreparedStatementCreator anonymous inner class:
PreparedStatement ps = con.prepareStatement(widgetInsert.toString(), generatedColumns);
I need to use my own ExclusionStrategy in GSON, so I have created this class:
public class DUExclusionStrategy implements ExclusionStrategy {
public boolean shouldSkipField(FieldAttributes f) {
Collection<Annotation> annots = f.getAnnotations();
for(Annotation a : annots) {
if(a.annotationType().equals(Expose.class)) {
return false;
}
}
return (f.getDeclaringClass() == BaseEntityImpl.class && f.getName().equals("creation"))
|| (f.getDeclaringClass() == BaseEntityImpl.class && f.getName().equals("creator"))
|| (f.getDeclaringClass() == BaseEntityImpl.class && f.getName().equals("modification"))
|| (f.getDeclaringClass() == BaseEntityImpl.class && f.getName().equals("modificator"));
}
public boolean shouldSkipClass(Class<?> clazz) {
return false;
}
}
I should not change anything in BaseEntityImpl, and there is this field in this class:
#OneToMany(mappedBy="parent", fetch=FetchType.LAZY) #OrderBy("ordinal")
private Set<T> children = new TreeSet<T>();
And because of calling f.getDeclaringClass() the application is throwing this exception:
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: cz.bach.dataframe2.domain.impl.BaseEntityImpl.children, could not initialize proxy - no Session
at org.hibernate.collection.internal.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:566)
at org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:186)
at org.hibernate.collection.internal.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:545)
at org.hibernate.collection.internal.AbstractPersistentCollection.read(AbstractPersistentCollection.java:124)
at org.hibernate.collection.internal.PersistentSet.iterator(PersistentSet.java:180)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:95)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:60)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:89)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:195)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:89)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:195)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:89)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:195)
at com.google.gson.Gson.toJson(Gson.java:593)
at com.google.gson.Gson.toJson(Gson.java:572)
at com.google.gson.Gson.toJson(Gson.java:527)
at com.google.gson.Gson.toJson(Gson.java:507)
at cz.bach.clients.du.model.service.DUSerializer.serialize(DUSerializer.java:23)
at cz.bach.clients.du.model.service.DURepository.save(DURepository.java:619)
at cz.bach.clients.du.model.service.DURepository.appendChild(DURepository.java:176)
at cz.bach.clients.du.model.service.DURepository.appendChild(DURepository.java:150)
at cz.bach.clients.du.model.service.DURepository$$FastClassByCGLIB$$f2fe0d5d.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:689)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:622)
at cz.bach.clients.du.model.service.DURepository$$EnhancerByCGLIB$$a27cbe9c.appendChild(<generated>)
at cz.bach.clients.du.ui.perspectives.main.DUDispatcher.add(DUDispatcher.java:261)
at cz.bach.archives.uiframe.actions.CommonAddAction.run(CommonAddAction.java:11)
at cz.bach.clients.du.ui.perspectives.main.DUToolbar$1.buttonClick(DUToolbar.java:71)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:510)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:164)
at com.vaadin.ui.AbstractComponent.fireEvent(AbstractComponent.java:1219)
at com.vaadin.ui.Button.fireClick(Button.java:567)
at com.vaadin.ui.Button.changeVariables(Button.java:223)
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.changeVariables(AbstractCommunicationManager.java:1460)
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariableBurst(AbstractCommunicationManager.java:1404)
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariables(AbstractCommunicationManager.java:1329)
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.doHandleUidlRequest(AbstractCommunicationManager.java:761)
at com.vaadin.terminal.gwt.server.CommunicationManager.handleUidlRequest(CommunicationManager.java:325)
at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(AbstractApplicationServlet.java:501)
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.RequestContextFilter.doFilterInternal(RequestContextFilter.java:83)
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:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
Can I solve this by easy and elegant way? I really don't see any reason why getDeclaringClass() should cause full inicialization of BaseEntityImpl ..
Thanks in advance!
In BaseEntityImpl Entity change fetchType Lazy to Eager i.e.
#OneToMany(mappedBy="parent", fetch=FetchType.EAGER)