Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type Exception report
- message Request processing failed; nested exception is javax.persistence.PersistenceException:
- description The server encountered an internal error that prevented it from fulfilling this request.
- exception
- org.springframework.web.util.NestedServletException: Request processing failed; nested exception is
- root cause
- javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not extract
- <?xml version="1.0" encoding="UTF-8"?>
- <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">
- <display-name>spring-mvc-crud-demo</display-name>
- <welcome-file-list>
- <welcome-file>index.jsp</welcome-file>
- <welcome-file>index.html</welcome-file>
- </welcome-file-list>
- <servlet>
- <servlet-name>dispatcher</servlet-name>
- <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
- <init-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>/WEB-INF/natural-healing-servlet.xml</param-value>
- </init-param>
- <load-on-startup>1</load-on-startup>
- </servlet>
- <servlet-mapping>
- <servlet-name>dispatcher</servlet-name>
- <url-pattern>/</url-pattern>
- </servlet-mapping>
- <!-- Load the spring security and natural-healing-servlet.xml files -->
- <listener>
- <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
- </listener>
- <context-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>
- /WEB-INF/natural-healing-servlet.xml
- /WEB-INF/security.xml
- </param-value>
- </context-param>
- <!-- This filters all URL patterns to use spring security -->
- <filter>
- <filter-name>springSecurityFilterChain</filter-name>
- <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
- </filter>
- <filter-mapping>
- <filter-name>springSecurityFilterChain</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
- </web-app>
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:context="http://www.springframework.org/schema/context"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xmlns:mvc="http://www.springframework.org/schema/mvc"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context.xsd
- http://www.springframework.org/schema/mvc
- http://www.springframework.org/schema/mvc/spring-mvc.xsd
- http://www.springframework.org/schema/tx
- http://www.springframework.org/schema/tx/spring-tx.xsd">
- <!-- Add support for component scanning -->
- <context:component-scan base-package="com.reviews.healing.natural" />
- <!-- Add support for conversion, formatting and validation support -->
- <mvc:annotation-driven/>
- <!-- Define Spring MVC view resolver -->
- <bean
- class="org.springframework.web.servlet.view.InternalResourceViewResolver">
- <property name="prefix" value="/WEB-INF/views/" />
- <property name="suffix" value=".jsp" />
- </bean>
- <!-- Step 1: Define Database DataSource / connection pool -->
- <bean id="myDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
- destroy-method="close">
- <property name="driverClass" value="com.mysql.jdbc.Driver" />
- <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/natural_healing_reviews?useSSL=false" />
- <property name="user" value="root" />
- <property name="password" value="password" />
- <!-- these are connection pool properties for C3P0 -->
- <property name="minPoolSize" value="5" />
- <property name="maxPoolSize" value="20" />
- <property name="maxIdleTime" value="30000" />
- </bean>
- <!-- Step 2: Setup Hibernate session factory -->
- <bean id="sessionFactory"
- class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
- <property name="dataSource" ref="myDataSource" />
- <property name="packagesToScan" value="com.reviews.healing.natural.entity" />
- <property name="hibernateProperties">
- <props>
- <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
- <prop key="hibernate.show_sql">true</prop>
- </props>
- </property>
- </bean>
- <!-- Step 3: Setup Hibernate transaction manager -->
- <bean id="myTransactionManager"
- class="org.springframework.orm.hibernate5.HibernateTransactionManager">
- <property name="sessionFactory" ref="sessionFactory"/>
- </bean>
- <!-- Step 4: Enable configuration of transactional behavior based on annotations -->
- <tx:annotation-driven transaction-manager="myTransactionManager" />
- <!-- Add support for reading web resources: css, images etc. -->
- <mvc:resources location="/resources/" mapping="/resources/**"></mvc:resources>
- </beans>
- <beans:beans xmlns="http://www.springframework.org/schema/security"
- xmlns:beans="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
- http://www.springframework.org/schema/security
- http://www.springframework.org/schema/security/spring-security.xsd">
- <!-- Allow access to all css/js etc. -->
- <http pattern="/resources/**" security="none"/>
- <!-- Used for creating roles -->
- <http>
- <csrf disabled="true"/>
- <intercept-url pattern="/account/create-account" access="permitAll"/>
- <intercept-url pattern="/**" access="hasRole('USER')" />
- <form-login />
- <logout/>
- </http>
- <!-- used to creating test users in the application -->
- <authentication-manager>
- <authentication-provider>
- <user-service>
- <user name="jimi" password="jimispassword" authorities="ROLE_USER, ROLE_ADMIN" />
- <user name="bob" password="bobspassword" authorities="ROLE_USER" />
- </user-service>
- </authentication-provider>
- </authentication-manager>
- </beans:beans>
- package com.reviews.healing.natural.dao;
- import java.util.List;
- import org.hibernate.query.Query;
- import org.hibernate.Session;
- import org.hibernate.SessionFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Repository;
- import com.reviews.healing.natural.entity.Condition;
- import com.reviews.healing.natural.entity.User;
- import com.reviews.healing.natural.util.ConditionsOrderByUtil;
- @Repository
- public class ConditionDAOImpl implements ConditionDAO {
- //need to inject the session factor
- @Autowired
- private SessionFactory sessionFactory;
- @Override
- public void saveCondition(Condition theCondition) {
- //get current hibernate session
- Session currentSession = sessionFactory.getCurrentSession();
- //save the condition to the database
- currentSession.save( theCondition );
- }
- @Override
- public List<Condition> listAllConditions(ConditionsOrderByUtil OrderBy) {
- //get current session hibernate
- Session currentSession = sessionFactory.getCurrentSession();
- //create the query
- Query<Condition> theQuery;
- //this uses the class ConditionsOrderByUtil to determine how the order of the conditions should show up.
- switch (OrderBy) {
- case ALPHABETICAL:
- theQuery = currentSession.createQuery("FROM Condition c ORDER BY c.name ASC", Condition.class);
- break;
- default:
- theQuery = currentSession.createQuery("FROM Condition c ORDER BY c.name ASC", Condition.class);
- break;
- }
- List<Condition> conditions = theQuery.getResultList();
- //execute the query
- return conditions;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement