Advertisement
Guest User

Untitled

a guest
Dec 1st, 2016
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.21 KB | None | 0 0
  1. type Exception report
  2.  
  3. message Request processing failed; nested exception is javax.persistence.PersistenceException:
  4.  
  5. description The server encountered an internal error that prevented it from fulfilling this request.
  6.  
  7. exception
  8. org.springframework.web.util.NestedServletException: Request processing failed; nested exception is
  9.  
  10. root cause
  11. javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not extract
  12.  
  13. <?xml version="1.0" encoding="UTF-8"?>
  14. <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  15. <display-name>spring-mvc-crud-demo</display-name>
  16.  
  17. <welcome-file-list>
  18. <welcome-file>index.jsp</welcome-file>
  19. <welcome-file>index.html</welcome-file>
  20. </welcome-file-list>
  21.  
  22. <servlet>
  23. <servlet-name>dispatcher</servlet-name>
  24. <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  25. <init-param>
  26. <param-name>contextConfigLocation</param-name>
  27. <param-value>/WEB-INF/natural-healing-servlet.xml</param-value>
  28. </init-param>
  29. <load-on-startup>1</load-on-startup>
  30. </servlet>
  31.  
  32. <servlet-mapping>
  33. <servlet-name>dispatcher</servlet-name>
  34. <url-pattern>/</url-pattern>
  35. </servlet-mapping>
  36.  
  37. <!-- Load the spring security and natural-healing-servlet.xml files -->
  38. <listener>
  39. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  40. </listener>
  41. <context-param>
  42. <param-name>contextConfigLocation</param-name>
  43. <param-value>
  44. /WEB-INF/natural-healing-servlet.xml
  45. /WEB-INF/security.xml
  46. </param-value>
  47. </context-param>
  48.  
  49. <!-- This filters all URL patterns to use spring security -->
  50. <filter>
  51. <filter-name>springSecurityFilterChain</filter-name>
  52. <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
  53. </filter>
  54.  
  55. <filter-mapping>
  56. <filter-name>springSecurityFilterChain</filter-name>
  57. <url-pattern>/*</url-pattern>
  58. </filter-mapping>
  59.  
  60. </web-app>
  61.  
  62. <?xml version="1.0" encoding="UTF-8"?>
  63. <beans xmlns="http://www.springframework.org/schema/beans"
  64. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  65. xmlns:context="http://www.springframework.org/schema/context"
  66. xmlns:tx="http://www.springframework.org/schema/tx"
  67. xmlns:mvc="http://www.springframework.org/schema/mvc"
  68. xsi:schemaLocation="
  69. http://www.springframework.org/schema/beans
  70. http://www.springframework.org/schema/beans/spring-beans.xsd
  71. http://www.springframework.org/schema/context
  72. http://www.springframework.org/schema/context/spring-context.xsd
  73. http://www.springframework.org/schema/mvc
  74. http://www.springframework.org/schema/mvc/spring-mvc.xsd
  75. http://www.springframework.org/schema/tx
  76. http://www.springframework.org/schema/tx/spring-tx.xsd">
  77.  
  78. <!-- Add support for component scanning -->
  79. <context:component-scan base-package="com.reviews.healing.natural" />
  80.  
  81. <!-- Add support for conversion, formatting and validation support -->
  82. <mvc:annotation-driven/>
  83.  
  84. <!-- Define Spring MVC view resolver -->
  85. <bean
  86. class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  87. <property name="prefix" value="/WEB-INF/views/" />
  88. <property name="suffix" value=".jsp" />
  89. </bean>
  90.  
  91. <!-- Step 1: Define Database DataSource / connection pool -->
  92. <bean id="myDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
  93. destroy-method="close">
  94. <property name="driverClass" value="com.mysql.jdbc.Driver" />
  95. <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/natural_healing_reviews?useSSL=false" />
  96. <property name="user" value="root" />
  97. <property name="password" value="password" />
  98.  
  99. <!-- these are connection pool properties for C3P0 -->
  100. <property name="minPoolSize" value="5" />
  101. <property name="maxPoolSize" value="20" />
  102. <property name="maxIdleTime" value="30000" />
  103. </bean>
  104.  
  105. <!-- Step 2: Setup Hibernate session factory -->
  106. <bean id="sessionFactory"
  107. class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
  108. <property name="dataSource" ref="myDataSource" />
  109. <property name="packagesToScan" value="com.reviews.healing.natural.entity" />
  110. <property name="hibernateProperties">
  111. <props>
  112. <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
  113. <prop key="hibernate.show_sql">true</prop>
  114. </props>
  115. </property>
  116. </bean>
  117.  
  118. <!-- Step 3: Setup Hibernate transaction manager -->
  119. <bean id="myTransactionManager"
  120. class="org.springframework.orm.hibernate5.HibernateTransactionManager">
  121. <property name="sessionFactory" ref="sessionFactory"/>
  122. </bean>
  123.  
  124. <!-- Step 4: Enable configuration of transactional behavior based on annotations -->
  125. <tx:annotation-driven transaction-manager="myTransactionManager" />
  126.  
  127. <!-- Add support for reading web resources: css, images etc. -->
  128. <mvc:resources location="/resources/" mapping="/resources/**"></mvc:resources>
  129.  
  130. </beans>
  131.  
  132. <beans:beans xmlns="http://www.springframework.org/schema/security"
  133. xmlns:beans="http://www.springframework.org/schema/beans"
  134. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  135. xsi:schemaLocation="http://www.springframework.org/schema/beans
  136. http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  137. http://www.springframework.org/schema/security
  138. http://www.springframework.org/schema/security/spring-security.xsd">
  139.  
  140.  
  141. <!-- Allow access to all css/js etc. -->
  142. <http pattern="/resources/**" security="none"/>
  143.  
  144. <!-- Used for creating roles -->
  145. <http>
  146. <csrf disabled="true"/>
  147. <intercept-url pattern="/account/create-account" access="permitAll"/>
  148.  
  149. <intercept-url pattern="/**" access="hasRole('USER')" />
  150. <form-login />
  151. <logout/>
  152. </http>
  153.  
  154.  
  155.  
  156. <!-- used to creating test users in the application -->
  157. <authentication-manager>
  158. <authentication-provider>
  159. <user-service>
  160. <user name="jimi" password="jimispassword" authorities="ROLE_USER, ROLE_ADMIN" />
  161. <user name="bob" password="bobspassword" authorities="ROLE_USER" />
  162. </user-service>
  163. </authentication-provider>
  164. </authentication-manager>
  165.  
  166.  
  167.  
  168. </beans:beans>
  169.  
  170. package com.reviews.healing.natural.dao;
  171.  
  172. import java.util.List;
  173.  
  174. import org.hibernate.query.Query;
  175. import org.hibernate.Session;
  176. import org.hibernate.SessionFactory;
  177. import org.springframework.beans.factory.annotation.Autowired;
  178. import org.springframework.stereotype.Repository;
  179.  
  180. import com.reviews.healing.natural.entity.Condition;
  181. import com.reviews.healing.natural.entity.User;
  182. import com.reviews.healing.natural.util.ConditionsOrderByUtil;
  183.  
  184. @Repository
  185. public class ConditionDAOImpl implements ConditionDAO {
  186.  
  187.  
  188. //need to inject the session factor
  189. @Autowired
  190. private SessionFactory sessionFactory;
  191.  
  192. @Override
  193. public void saveCondition(Condition theCondition) {
  194.  
  195.  
  196. //get current hibernate session
  197. Session currentSession = sessionFactory.getCurrentSession();
  198.  
  199. //save the condition to the database
  200. currentSession.save( theCondition );
  201.  
  202. }
  203.  
  204. @Override
  205. public List<Condition> listAllConditions(ConditionsOrderByUtil OrderBy) {
  206. //get current session hibernate
  207. Session currentSession = sessionFactory.getCurrentSession();
  208.  
  209. //create the query
  210. Query<Condition> theQuery;
  211.  
  212. //this uses the class ConditionsOrderByUtil to determine how the order of the conditions should show up.
  213. switch (OrderBy) {
  214. case ALPHABETICAL:
  215. theQuery = currentSession.createQuery("FROM Condition c ORDER BY c.name ASC", Condition.class);
  216. break;
  217. default:
  218. theQuery = currentSession.createQuery("FROM Condition c ORDER BY c.name ASC", Condition.class);
  219. break;
  220. }
  221.  
  222. List<Condition> conditions = theQuery.getResultList();
  223.  
  224. //execute the query
  225. return conditions;
  226. }
  227.  
  228. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement