Project with support springMVC.
The query emphasizes FROM ('FROM' unexpected). Why?
@Repository public class BookmarksDAOImpl implements BookmarksDAO{ /*Настроить логирование в файл*/ private static final Logger logger = LoggerFactory.getLogger(BookmarksDAOImpl.class); private SessionFactory sessionFactory; public void setSessionFactory(SessionFactory sessionFactory) { this.sessionFactory = sessionFactory; } @Override @SuppressWarnings("unchecked") public List<Bookmarks> listBookmarks() { Session session = sessionFactory.getCurrentSession(); List<Bookmarks> listBookmarks = session.createQuery("FROM Bookmarks").list(); return listBookmarks; } }
Class-entity (I will copy everything, except for set / get methods):
@Entity @Table(name="bookmarks") public class Bookmarks { @Id @Column(name="id") @GeneratedValue(strategy = GenerationType.IDENTITY) private int id; @Column(name="name") private String name; @Column(name="Date") private Calendar calendar; @Column(name="Reference") private String reference; @Column(name="Description") private String description;
The database is called Bookmarks, it has one table bookmarks.
<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/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <context:component-scan base-package="net"/> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="WEB-INF/view/"/> <property name="suffix" value=".jsp"/> </bean> <!-- Connection DB --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="com.mysql.jdbc.Driver"/> <property name="url" value="jdbc:mysql://localhost:3306/Bookmarks"/> <property name="username" value="root"/> <property name="password" value="rootpasswordgiven"/> </bean> <!-- Hibernate 5--> <bean id="hibernate5AnnotatedSessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="annotatedClasses"> <list> <value>net.model.Bookmarks</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="show_sql">true</prop> </props> </property> </bean> <!-- Create beans DAO and Service level--> <bean id="bookmarksDao" class="net.dao.BookmarksDAOImpl"> <property name="sessionFactory" ref="hibernate5AnnotatedSessionFactory"/> </bean> <bean id="bookmarksService" class="net.service.BookmarksServiceImpl"> <property name="bookmarksDAO" ref="bookmarksDao"/> </bean> <!-- Create bean transactionManager--> <bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager"> <property name="sessionFactory" ref="hibernate5AnnotatedSessionFactory"/> </bean> <tx:annotation-driven transaction-manager="transactionManager"/> <mvc:default-servlet-handler/> <mvc:annotation-driven/> </beans>
SELECT * FROM bookmarks
- Sergi<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
. Added to the question. - Maks Ohotnikov