Я новичок в Spring Framework. Разработка веб-приложения с использованием Spring 4.3 и Hibernate 4.
Я настроил необходимые компоненты.
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName"
value="${oracle.driver-calss}" />
<property name="url" value="${oracle.Url}" />
<property name="username" value="${oracle.userName}" />
<property name="password" value="${oracle.password}" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${oracle.dialect}</prop>
<prop key="hibernate.hbm2ddl.auto">${oracle.hbm2ddl}</prop>
<prop key="hibernate.show-sql">${oracle.show-sql}</prop>
</props>
</property>
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="com.wmosIIBL.model"></property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:annotation-driven />
Это мой класс обслуживания
@Service
public class ItemIBLService {
@Autowired
ItemIBLDaoImpl itemIBLDaoImpl;
@Transactional
public ItemInvnByLcn getItemIBLByDspLocn(String dspLocn) {
ItemInvnByLcn itemInvnByLcn = null;
try {
itemIBLDaoImpl.getIBLByDspLocn(dspLocn);
} catch (DataAccessException dataAccessException) {
System.out.println(dataAccessException.getMessage().toString());
}
return itemInvnByLcn;
}
}
Код DAO Impl: Я специально сделал несколько ошибок, чтобы создать исключение. Поэтому, пожалуйста, игнорируйте ошибки в коде и помогите мне найти, как перехватить выброшенное исключение.
@Repository
public class ItemIBLDaoImpl {
@Autowired
SessionFactory sessionFactory;
public ItemInvnByLcn getIBLByDspLocn(String dspLocn) {
Session currentSession = sessionFactory.getCurrentSession();
SQLQuery sqlQuery = currentSession.createSQLQuery("SELECT * FROM WHERE ITEMINVNBYLOCN WHERE LOCATION= :DSPLOCN");
sqlQuery.setParameter("SDPLOCN", dspLocn);
List iiblList = sqlQuery.list();
System.out.println(iiblList.toString());
return (ItemInvnByLcn) iiblList.get(0);
}
}
Hibernate выдает следующее исключение, которое я не могу перехватить в классе обслуживания.
org.hibernate.QueryParameterException: could not locate named parameter [SDPLOCN]
at org.hibernate.engine.query.spi.ParameterMetadata.getNamedParameterDescriptor(ParameterMetadata.java:148)
at org.hibernate.engine.query.spi.ParameterMetadata.getNamedParameterExpectedType(ParameterMetadata.java:165)
at org.hibernate.internal.AbstractQueryImpl.determineType(AbstractQueryImpl.java:523)
at org.hibernate.internal.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:493)
at com.wmosIIBL.dao.ItemIBLDaoImpl.getIBLByDspLocn(ItemIBLDaoImpl.java:22)
at com.wmosIIBL.service.ItemIBLService.getItemIBLByDspLocn(ItemIBLService.java:22)
at com.wmosIIBL.service.ItemIBLService$$FastClassBySpringCGLIB$$51d359cb.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:721)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:656)
at com.wmosIIBL.service.ItemIBLService$$EnhancerBySpringCGLIB$$eecd7652.getItemIBLByDspLocn(<generated>)
at com.wmosIIBL.controller.ItemIBLController.getItemInvnByLocn(ItemIBLController.java:30)
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.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:180)
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:963)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
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:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:494)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:1025)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1136)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
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)
Мне кажется, я что-то упустил при использовании. Пожалуйста, дайте мне знать, почему я не могу поймать исключение, которое выдает Hibernate в классе обслуживания Spring, хотя я использую @Service и @Transactional в слое сервиса и @Repository в слое Dao.