String temp[]=bookName.split(" ");
ArrayList list=new ArrayList();
try {
con=ds.getConnection();
pst=con.prepareStatement("select distinct book_name from booksinventory");
rs=pst.executeQuery();
for(int i=0;i<temp.length;i++)
{
while(rs.next())
{
//System.out.println(rs.getString(1)+" contains "+temp[i]);
line no 631 --> System.out.println(rs.getString(1)+" contains "+temp[i]+":"+(rs.getString(1).toUpperCase()).contains(temp[i].toUpperCase()));
if((rs.getString(1).toUpperCase()).contains(temp[i].toUpperCase()))
{
list.add(rs.getString(1));
System.out.println(list);
}
}
rs.beforeFirst();
}
System.out.println(list);
Set<String> set=new HashSet<String>();
set.addAll(list);
list.removeAll(list);
list.addAll(set);
list.removeAll(Collections.singleton(null));
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
Here I'm trying to search through my records to check whether a particular set of keywords are present in the record. I tried almost everything cant figure out the error.. I think its with the statement "rs.beforeFirst()" because it is only printing for the first iteration.. Following is from the console..
16:55:06,240 INFO [STDOUT] Let us C contains let:true
16:55:06,240 INFO [STDOUT] [Let us C]
16:55:06,240 INFO [STDOUT] Let us C++ contains let:true
16:55:06,240 INFO [STDOUT] [Let us C, Let us C++]
16:55:06,240 INFO [STDOUT] Let us HTML contains let:true
16:55:06,240 INFO [STDOUT] [Let us C, Let us C++, Let us HTML]
16:55:06,240 INFO [STDOUT] dfgdfg contains let:false
16:55:06,240 INFO [STDOUT] digital electronics contains let:false
16:55:06,240 INFO [STDOUT] java contains let:false
16:55:06,241 INFO [STDOUT] oops contains let:false
16:55:06,241 INFO [STDOUT] quantum computing contains let:false
16:55:06,241 INFO [STDOUT] sdf contains let:false
16:55:06,241 ERROR [[SearchBooksCombo]] Servlet.service() for servlet SearchBooksCombo threw exception
java.lang.NullPointerException
at com.classes.dao.LibraryDAO.getMatchingBooks(LibraryDAO.java:631)
at com.classes.servlets.SearchBooksCombo.doGet(SearchBooksCombo.java:37)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:654)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:557)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:481)
at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:968)
at org.apache.jsp.addCopy_jsp._jspService(addCopy_jsp.java:80)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:336)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
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:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
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:157)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
at java.lang.Thread.run(Unknown Source)
16:55:06,241 ERROR [[jsp]] Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
at com.classes.dao.LibraryDAO.getMatchingBooks(LibraryDAO.java:631)
at com.classes.servlets.SearchBooksCombo.doGet(SearchBooksCombo.java:37)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:654)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:557)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:481)
at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:968)
at org.apache.jsp.addCopy_jsp._jspService(addCopy_jsp.java:80)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:336)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
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:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
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:157)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
at java.lang.Thread.run(Unknown Source)
16:55:06,242 INFO [CachedConnectionManager] Closing a connection for you. Please close them yourself: org.jboss.resource.adapter.jdbc.jdk5.WrappedConnectionJDK5#52fdeb
java.lang.Throwable: STACKTRACE
at org.jboss.resource.connectionmanager.CachedConnectionManager.registerConnection(CachedConnectionManager.java:290)
at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:423)
at org.jboss.resource.connectionmanager.BaseConnectionManager2$ConnectionManagerProxy.allocateConnection(BaseConnectionManager2.java:849)
at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:89)
at com.classes.dao.LibraryDAO.getMatchingBooks(LibraryDAO.java:622)
at com.classes.servlets.SearchBooksCombo.doGet(SearchBooksCombo.java:37)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:654)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:557)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:481)
at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:968)
at org.apache.jsp.addCopy_jsp._jspService(addCopy_jsp.java:80)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:336)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
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:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
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:157)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
at java.lang.Thread.run(Unknown Source)
"because it is only printing for the first iteration."
From the ResultSet javadoc.
A default ResultSet object is not updatable and has a cursor that moves forward only. Thus, you can iterate through it only once and only from the first row to the last row. It is possible to produce ResultSet objects that are scrollable and/or updatable. The following code fragment, in which con is a valid Connection object, illustrates how to make a result set that is scrollable and insensitive to updates by others, and that is updatable. See ResultSet fields for other options.
Statement stmt = con.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
ResultSet rs = stmt.executeQuery("SELECT a, b FROM TABLE2");
// rs will be scrollable, will not show changes made by others,
// and will be updatable
Here's how I would write that class, based on what you've posted:
package persistence;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
/**
* BookDao description here
* #author Michael
* #link http://stackoverflow.com/questions/21380043/javaresultset-error#21380043
* #since 1/27/14 6:51 AM
*/
public class BookDao {
public static final String SELECT_BOOK_NAMES = "select distinct book_name from booksinventory";
private Connection con;
public BookDao(Connection con) {
this.con = con;
}
public List<String> getAllBookNamesByKeywords() throws SQLException {
List<String> list = new ArrayList<String>();
PreparedStatement ps = null;
ResultSet rs = null;
try {
ps = con.prepareStatement(SELECT_BOOK_NAMES);
rs = ps.executeQuery();
while(rs.next()) {
list.add(rs.getString(1));
}
} finally {
DatabaseUtils.close(rs);
DatabaseUtils.close(ps);
}
return list;
}
}
You do a lot of things that are either unnecessary or incorrect.
Related
I was using Apache Commons DBCP (commons-dbcp-1.2.2.jar) Connection pool and importing org.apache.commons.dbcp.DelegatingConnection.
Due to some performance isues, I upgraded to commons-dbcp2-2.1.1.jar and imported org.apache.commons.dbcp2.DelegatingConnection.
But while executing getting following Exception
java.lang.ClassCastException: org.apache.commons.dbcp.DelegatingCallableStatement cannot be cast to oracle.jdbc.OracleCallableStatement
Any idea why is this coming.
Java Code
public static Connection getOracleConnection(java.sql.Connection con) throws SQLException
{
Connection oracleCon = null;
if(con instanceof com.p6spy.engine.spy.P6Connection)
{
oracleCon = (oracle.jdbc.OracleConnection)((P6Connection)con).getJDBC();
}
else if(con instanceof P6LogConnection)
{
oracleCon = (oracle.jdbc.OracleConnection)((P6LogConnection)con).getJDBC();
}
else if(con instanceof DelegatingConnection)
{
Object innerMostObj = ((DelegatingConnection)con).getInnermostDelegate();
if(innerMostObj instanceof oracle.jdbc.OracleConnection )
{
oracleCon = (oracle.jdbc.OracleConnection)innerMostObj;
}
else if(innerMostObj instanceof P6LogConnection)
{
oracleCon = ((P6LogConnection)innerMostObj).getJDBC();
}
else if(innerMostObj instanceof P6Connection)
{
oracleCon = ((P6Connection)innerMostObj).getJDBC();
}
}
else
{
oracleCon = con;
}
return oracleCon;
}
StackTrace
[ERROR] 2015-10-20 08:55:49 com.jatin.ebook.presentation.actions.LoginPersonalizationAction.execute(LoginPersonalizationAction.java:933) - Exception occured in Personalizationjava.lang.Exception: com.jatin.ebook.common.exception.EBookException: java.lang.ClassCastException: org.apache.commons.dbcp.DelegatingCallableStatement cannot be cast to oracle.jdbc.OracleCallableStatement
[INFO ] 2015-10-20 08:55:49 com.jatin.ebook.presentation.actions.LoginPersonalizationAction.loadLoginPageResources(LoginPersonalizationAction.java:1132) - calling loadLoginPageResources: languageID[-1]
[INFO ] 2015-10-20 08:55:49 com.jatin.ebook.flashremoting.util.EBookViewerServiceUtil.getTagValueFromLanguageResourcesBasedOnPlatform(EBookViewerServiceUtil.java:3129) - getTagValueFromLanguageResourcesBasedOnPlatform :: languageID:-1, platform:null
[INFO ] 2015-10-20 08:55:49 com.jatin.ebook.flashremoting.util.EBookViewerServiceUtil.getTagValueFromLanguageResourcesBasedOnPlatform(EBookViewerServiceUtil.java:3139) - platform id is null
[INFO ] 2015-10-20 08:55:49 com.jatin.ebook.flashremoting.util.EBookViewerServiceUtil.getTagValueFromLanguageResources(EBookViewerServiceUtil.java:3147) - getLanguageResources(category = ui_jsp, languageID = -1) is invoked...
[INFO ] 2015-10-20 08:55:49 com.jatin.ebook.services.appservices.LanguageStringService.getTagValueFromLanguageResources(LanguageStringService.java:621) - getTagValueFromLanguageResources (category: ui_jsp,languageID: -1,key: null, platformID0) is requested
[INFO ] 2015-10-20 08:55:49 com.jatin.ebook.services.appservices.LanguageStringService.getLanguageResourcesXML(LanguageStringService.java:494) - getLanguageResourcesXML (category:ui_jsp,languageID:-1,key:null,platformID:0) is requested
[ERROR] 2015-10-20 08:55:49 com.jatin.ebook.services.appservices.LanguageStringService.getTagValueFromLanguageResources(LanguageStringService.java:643) - Exception occurred in getTagValueFromLanguageResources
java.lang.ClassCastException: org.apache.commons.dbcp.DelegatingCallableStatement cannot be cast to oracle.jdbc.OracleCallableStatement
at com.jatin.ebook.persistence.util.StoredProcUtil.registerAndSetProcParameters(StoredProcUtil.java:280)
at com.jatin.ebook.persistence.util.StoredProcUtil.executeStoredProc(StoredProcUtil.java:82)
at com.jatin.ebook.services.appservices.LanguageStringService.getLanguageResourcesXML(LanguageStringService.java:556)
at com.jatin.ebook.services.appservices.LanguageStringService.getTagValueFromLanguageResources(LanguageStringService.java:627)
at com.jatin.ebook.services.controller.LanguageStringProcessorController.executeController(LanguageStringProcessorController.java:92)
at com.jatin.ebook.services.EBookSession.executeEvent(EBookSession.java:51)
at com.jatin.ebook.common.delegate.EBookDelegate.executeEvent(EBookDelegate.java:17)
at com.jatin.ebook.flashremoting.util.EBookViewerServiceUtil.getTagValueFromLanguageResources(EBookViewerServiceUtil.java:3166)
at com.jatin.ebook.flashremoting.util.EBookViewerServiceUtil.getTagValueFromLanguageResourcesBasedOnPlatform(EBookViewerServiceUtil.java:3140)
at com.jatin.ebook.presentation.actions.LoginPersonalizationAction.loadLoginPageResources(LoginPersonalizationAction.java:1133)
at com.jatin.ebook.presentation.actions.LoginPersonalizationAction.execute(LoginPersonalizationAction.java:935)
at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
at org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
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.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
at org.apache.struts.chain.commands.servlet.PerformForward.handleAsForward(PerformForward.java:113)
at org.apache.struts.chain.commands.servlet.PerformForward.perform(PerformForward.java:96)
at org.apache.struts.chain.commands.AbstractPerformForward.execute(AbstractPerformForward.java:54)
at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
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 com.jatin.ebook.presentation.filter.EBookAccessFilter.doFilter(EBookAccessFilter.java:686)
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.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:470)
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.AccessLogValve.invoke(AccessLogValve.java:615)
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:745)
[ERROR] 2015-10-20 08:55:49 com.jatin.ebook.services.EBookSession.executeEvent(EBookSession.java:66) - EBookException in executeEvent:
com.jatin.ebook.common.exception.EBookException: java.lang.ClassCastException: org.apache.commons.dbcp.DelegatingCallableStatement cannot be cast to oracle.jdbc.OracleCallableStatement
at com.jatin.ebook.services.appservices.LanguageStringService.getTagValueFromLanguageResources(LanguageStringService.java:644)
at com.jatin.ebook.services.controller.LanguageStringProcessorController.executeController(LanguageStringProcessorController.java:92)
at com.jatin.ebook.services.EBookSession.executeEvent(EBookSession.java:51)
at com.jatin.ebook.common.delegate.EBookDelegate.executeEvent(EBookDelegate.java:17)
at com.jatin.ebook.flashremoting.util.EBookViewerServiceUtil.getTagValueFromLanguageResources(EBookViewerServiceUtil.java:3166)
at com.jatin.ebook.flashremoting.util.EBookViewerServiceUtil.getTagValueFromLanguageResourcesBasedOnPlatform(EBookViewerServiceUtil.java:3140)
at com.jatin.ebook.presentation.actions.LoginPersonalizationAction.loadLoginPageResources(LoginPersonalizationAction.java:1133)
at com.jatin.ebook.presentation.actions.LoginPersonalizationAction.execute(LoginPersonalizationAction.java:935)
at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
at org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
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.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
at org.apache.struts.chain.commands.servlet.PerformForward.handleAsForward(PerformForward.java:113)
at org.apache.struts.chain.commands.servlet.PerformForward.perform(PerformForward.java:96)
at org.apache.struts.chain.commands.AbstractPerformForward.execute(AbstractPerformForward.java:54)
at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
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 com.jatin.ebook.presentation.filter.EBookAccessFilter.doFilter(EBookAccessFilter.java:686)
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.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:470)
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.AccessLogValve.invoke(AccessLogValve.java:615)
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:745)
Caused by: java.lang.ClassCastException: org.apache.commons.dbcp.DelegatingCallableStatement cannot be cast to oracle.jdbc.OracleCallableStatement
at com.jatin.ebook.persistence.util.StoredProcUtil.registerAndSetProcParameters(StoredProcUtil.java:280)
at com.jatin.ebook.persistence.util.StoredProcUtil.executeStoredProc(StoredProcUtil.java:82)
at com.jatin.ebook.services.appservices.LanguageStringService.getLanguageResourcesXML(LanguageStringService.java:556)
at com.jatin.ebook.services.appservices.LanguageStringService.getTagValueFromLanguageResources(LanguageStringService.java:627)
... 53 more
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
Hi can someone please help why this is giving an error when trying to display the values in a JSP page. I don't have any number been converted or String been converted to Number, however I get NumberFormatException
my Servlet getting the request to display a user record
if(action.equalsIgnoreCase("update")){
System.out.println("Came into Update");
userId=(int) Integer.parseInt(request.getParameter("userid"));
nbId=request.getParameter("nbId").trim();
System.out.println("User iD and NBid: "+ userId + nbId);
User user=new User();
user.setUser_id(userId);
user.setUser_nbk(nbId);
List userRecords=UserDAO.getUserRecord(user);
request.setAttribute("userRecords", userRecords);
List owningOrg=Owning_Org_DB.getOwningOrgRecords();
request.setAttribute("owningOrg", owningOrg);
request.getRequestDispatcher("WEB-INF/JSP/TableMaintenance/UserNewAdd.jsp").forward(request, response);
POJO:
#Entity
#Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
public class User {
#Id
private int user_id;
private String user_first_name;
private String user_middle_name;
private String user_last_name;
//getters and setters methos
}
DAO:
public static List getUserRecord(User obj){
Logger lo=LoggerFactory.getLogger("UserDAO.getUserRecord");
Session session= Annotationsessionfactory.getAnnotationSession();
Transaction tx=session.beginTransaction();
lo.debug("Request for A user Record");
//List<User> recList=new ArrayList<User>();
List recList=null;
try{
//String userRecord="from User";
Criteria userList=session.createCriteria(User.class)
.add(Restrictions.eq("user_nbk", obj.getUser_nbk()))
.add(Restrictions.eq("user_id", obj.getUser_id()));
recList=userList.list();
System.out.println(recList.size());
}catch (Exception e){
lo.info("Exception Occured in UserDAO.getUserRecord");
lo.debug("Exception Occured in UserDAO.getUserRecord:"+e);
tx.rollback();
}finally{
session.close();
lo.info("Session Closed in UserDAO.userRecordslist finally block: ");
}
lo.debug("Record was sent to the requesting servlet or method: "+ recList);
return recList;
}
JSP Page
<table>
<tr>
<td>First Name</td>
<td><input type="text" id="firstname" name="firstname" maxlength="80" value="">${userRecords.user_first_name}</td>
</tr>
<tr>
<td>Middle Name</td>
<td><input type="text" id="middlename" name="middlename" maxlength="80" value="${userRecords.user_middle_name}"></td>
.......
Exception I get:
SEVERE: Servlet.service() for servlet jsp threw exception
**java.lang.NumberFormatException: For input string: "user_first_name"**
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:447)
at java.lang.Integer.parseInt(Integer.java:497)
at javax.el.ListELResolver.coerce(ListELResolver.java:166)
at javax.el.ListELResolver.getValue(ListELResolver.java:51)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
at org.apache.el.parser.AstValue.getValue(AstValue.java:123)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:938)
at org.apache.jsp.WEB_002dINF.JSP.TableMaintenance.UserNewAdd_jsp._jspService (UserNewAdd_jsp.java:77)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
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.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
at com.servicedbUpdate.UserUpdateDB_NewAdds.doPost(UserUpdateDB_NewAdds.java:79)
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.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.Http11AprProcessor.process(Http11AprProcessor.java:879)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:600)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1703)
at java.lang.Thread.run(Thread.java:619)
Feb 13, 2013 10:30:49 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet UserUpdateDB_NewAdds threw exception
**java.lang.NumberFormatException: For input string: "user_first_name"**
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:447)
at java.lang.Integer.parseInt(Integer.java:497)
at javax.el.ListELResolver.coerce(ListELResolver.java:166)
at javax.el.ListELResolver.getValue(ListELResolver.java:51)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
at org.apache.el.parser.AstValue.getValue(AstValue.java:123)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:938)
at org.apache.jsp.WEB_002dINF.JSP.TableMaintenance.UserNewAdd_jsp._jspService(UserNewAdd_jsp.java:77)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
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.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
at com.servicedbUpdate.UserUpdateDB_NewAdds.doPost(UserUpdateDB_NewAdds.java:79)
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.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.Http11AprProcessor.process(Http11AprProcessor.java:879)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:600)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1703)
at java.lang.Thread.run(Thread.java:619)
The ${userRecords} here
${userRecords.user_first_name}
${userRecords.user_middle_name}
is a List<User>, however you're attempting to access it as if it's a single User. This is not valid. In EL, a List can only be accessed with an integer index, indicating the position of the list item you'd like to access, like so
${userRecords[0].user_first_name}
${userRecords[0].user_middle_name}
The exception is also basically telling that it expected an integer value instead of a string value. If you look closer at the stack trace, you'll see that a ListELResolver is involved.
However, your concrete problem is bigger. You should actually be iterating over the list. Use the JSTL <c:forEach> for that. E.g. (simplified from your odd code snippet):
<table>
<c:forEach items="${userRecords}" var="user">
<tr>
<td>${user.user_first_name}</td>
<td>${user.user_middle_name}</td>
</tr>
</c:forEach>
</table>
(note: keep the XSS attack hole in mind if you really intend to redisplay them as input values)
By the way, I'd work on your Java code conventions. Those underscores are really not Java-ish.
This is my method which talks to the database with JPA:
public Collection<ModuleConnection> getConnections(int parentModuleId) {
Query query = em.createQuery("SELECT moduleConnection FROM ModuleConnection As moduleConnection WHERE moduleConnection.parentModule = :parentModuleId");
query.setParameter("parentModuleId", parentModuleId);
List<ModuleConnection> cons = query.getResultList();
return cons;
}
I am calling this method like this:
Collection<ModuleConnection> connections = bh.getConnections(module.getModuleId());
Everytime I do this, I get this exception:
java.lang.IllegalArgumentException: Can not set int field xyz.BomModule.moduleId to java.lang.Integer
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:164)
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:168)
at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:55)
at sun.reflect.UnsafeIntegerFieldAccessorImpl.getInt(UnsafeIntegerFieldAccessorImpl.java:56)
at sun.reflect.UnsafeIntegerFieldAccessorImpl.get(UnsafeIntegerFieldAccessorImpl.java:36)
at java.lang.reflect.Field.get(Field.java:372)
at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:55)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:206)
at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:3619)
at org.hibernate.persister.entity.AbstractEntityPersister.isTransient(AbstractEntityPersister.java:3335)
at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:204)
at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:241)
at org.hibernate.type.EntityType.getIdentifier(EntityType.java:430)
at org.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:110)
at org.hibernate.param.NamedParameterSpecification.bind(NamedParameterSpecification.java:61)
at org.hibernate.loader.hql.QueryLoader.bindParameterValues(QueryLoader.java:514)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1589)
at org.hibernate.loader.Loader.doQuery(Loader.java:696)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at org.hibernate.loader.Loader.doList(Loader.java:2228)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2125)
at org.hibernate.loader.Loader.list(Loader.java:2120)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:401)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:361)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1148)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:67)
at xyz.getConnections(BomHandling.java:194)
at org.apache.jsp.js.jquery_002dtreeview.demo.bom_005fexample_jsp._jspService(bom_005fexample_jsp.java:222)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:322)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:249)
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.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
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:722)
11:38:03,373 ERROR [CachedConnectionValve] Application error: jsp did not complete its transaction
This is how the table looks like:
CREATE TABLE "MODULECONNECTION"
(
"ID" NUMBER(10,0) NOT NULL ENABLE,
"QUANTITY" NUMBER(10,0) NOT NULL ENABLE,
"PARENTMODULE_MODULEID" NUMBER(10,0),
"SUBMODULE_MODULEID" NUMBER(10,0)
)
Any idea how I can fix this?
I think your query should just be
SELECT moduleConnection FROM ModuleConnection As moduleConnection
WHERE moduleConnection.parentModule.id = :parentModuleId
You could use your original query if the argument of the query was of type Module (the type of the associated entity, and not the type of its ID)
Good Morning.
I've got a problem using Hibernate 3.0.0, JBoss 5.1.0GA and jdk1.6
here is a log of error:
10:53:11,841 WARN [QueryTranslatorImpl] firstResult/maxResults specified with collection fetch; applying in memory!
10:53:11,909 ERROR [ActionQueue] could not release a cache lock
org.hibernate.cache.CacheException: java.lang.IllegalStateException: Transaction TransactionImple < ac, BasicAction: -53e95dff:de00:4f30f3fb:91 status: ActionStatus.COMMITTED > is not in a valid state to be invoking cache operations on.
at org.hibernate.cache.jbc2.util.CacheHelper.removeAll(CacheHelper.java:380)
at org.hibernate.cache.jbc2.util.CacheHelper.removeAll(CacheHelper.java:360)
at org.hibernate.cache.jbc2.access.TransactionalAccessDelegate.evictOrRemoveAll(TransactionalAccessDelegate.java:146)
at org.hibernate.cache.jbc2.access.TransactionalAccessDelegate.evictAll(TransactionalAccessDelegate.java:142)
at org.hibernate.cache.jbc2.entity.TransactionalAccess.evictAll(TransactionalAccess.java:102)
at org.hibernate.impl.SessionFactoryImpl.evictEntity(SessionFactoryImpl.java:870)
at org.hibernate.action.BulkOperationCleanupAction.evictEntityRegions(BulkOperationCleanupAction.java:153)
at org.hibernate.action.BulkOperationCleanupAction.afterTransactionCompletion(BulkOperationCleanupAction.java:132)
at org.hibernate.engine.ActionQueue.afterTransactionCompletion(ActionQueue.java:198)
at org.hibernate.impl.SessionImpl.afterTransactionCompletion(SessionImpl.java:451)
at org.hibernate.jdbc.JDBCContext.afterTransactionCompletion(JDBCContext.java:252)
at org.hibernate.transaction.CacheSynchronization.afterCompletion(CacheSynchronization.java:117)
at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.afterCompletion(SynchronizationImple.java:123)
at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.afterCompletion(TwoPhaseCoordinator.java:381)
at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:99)
at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:177)
at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1423)
at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:137)
at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:75)
at org.jboss.tm.usertx.client.ServerVMClientUserTransaction.commit(ServerVMClientUserTransaction.java:162)
at org.jboss.seam.transaction.UTTransaction.commit(UTTransaction.java:52)
at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:613)
at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:604)
at org.jboss.seam.jsf.SeamPhaseListener.handleTransactionsAfterPhase(SeamPhaseListener.java:345)
at org.jboss.seam.jsf.SeamPhaseListener.afterServletPhase(SeamPhaseListener.java:245)
at org.jboss.seam.jsf.SeamPhaseListener.afterPhase(SeamPhaseListener.java:196)
at com.sun.faces.lifecycle.Phase.handleAfterPhase(Phase.java:175)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:114)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
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.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
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:619)
Caused by: java.lang.IllegalStateException: Transaction TransactionImple < ac, BasicAction: -53e95dff:de00:4f30f3fb:91 status: ActionStatus.COMMITTED > is not in a valid state to be invoking cache operations on.
at org.jboss.cache.interceptors.TxInterceptor.registerTransaction(TxInterceptor.java:727)
at org.jboss.cache.interceptors.TxInterceptor.attachGlobalTransaction(TxInterceptor.java:474)
at org.jboss.cache.interceptors.TxInterceptor.attachGtxAndPassUpChain(TxInterceptor.java:300)
at org.jboss.cache.interceptors.TxInterceptor.handleDefault(TxInterceptor.java:283)
at org.jboss.cache.commands.AbstractVisitor.visitRemoveNodeCommand(AbstractVisitor.java:75)
at org.jboss.cache.commands.write.RemoveNodeCommand.acceptVisitor(RemoveNodeCommand.java:125)
at org.jboss.cache.interceptors.base.CommandInterceptor.invokeNextInterceptor(CommandInterceptor.java:116)
at org.jboss.cache.interceptors.base.CommandInterceptor.handleDefault(CommandInterceptor.java:131)
at org.jboss.cache.commands.AbstractVisitor.visitRemoveNodeCommand(AbstractVisitor.java:75)
at org.jboss.cache.commands.write.RemoveNodeCommand.acceptVisitor(RemoveNodeCommand.java:125)
at org.jboss.cache.interceptors.base.CommandInterceptor.invokeNextInterceptor(CommandInterceptor.java:116)
at org.jboss.cache.interceptors.InvocationContextInterceptor.handleAll(InvocationContextInterceptor.java:178)
at org.jboss.cache.interceptors.InvocationContextInterceptor.visitRemoveNodeCommand(InvocationContextInterceptor.java:88)
at org.jboss.cache.commands.write.RemoveNodeCommand.acceptVisitor(RemoveNodeCommand.java:125)
at org.jboss.cache.interceptors.InterceptorChain.invoke(InterceptorChain.java:287)
at org.jboss.cache.invocation.CacheInvocationDelegate.removeNode(CacheInvocationDelegate.java:478)
at org.jboss.ha.cachemanager.CacheManagerManagedCache.removeNode(CacheManagerManagedCache.java:317)
at org.hibernat
e.cache.jbc2.util.CacheHelper.removeAll(CacheHelper.java:378)
... 70 more
And here is a code that cause that error:
public void query(String query)
{
manager.createNativeQuery(query).executeUpdate();
manager.clear();
manager.flush();
}
Error shows every time I do insert/update/delete query.
If you need more info please ask.
Thank You in advance.
I finally found a workaround. In a seperate EJB, use the following code:
public class MyEJB {
#PersistenceContext
private Session session;
public final void update(int param) {
this.session.doWork(new UpdateWork(param));
}
private class UpdateWork implements Work {
private final int param;
public UpdateWork(int param) {
this.param = param;
}
/**
* {#inheritDoc}
*/
#Override
public void execute(Connection connection) throws SQLException {
PreparedStatement statement = connection.prepareStatement(query);
int updated = statement.executeUpdate();
statement.setInt(1,param);
if (updated > 0) {
// stuff
}
}
}
}
It seems that your transaction is already committed. Maybe you should create a new transaction to perform this operation in.
This is a Hibernate bug:
https://hibernate.onjira.com/browse/HHH-3818
Upgrading your version of Hibernate to a version greater than 3.3.2 should resolve the issue.