Hallo
Habe eine kleine Anwendung (siehe Anhang) mit Spring + Hibernate(JPA) auf Wildfly8 erstellt. Dabei möchte ich eine Liste von Studenten auf einer jsp-Seite anzeigen lassen (students.jsp). Allerdings erhalte ich einen Fehler java.lang.IllegalArgumentException: No query defined for that name [Student.findAll]. Warum? Am Dao / Service kann es eigentlich nicht liegen, denn - als Konsolenanwendung konfiguriert - läuft es.
Die jsp-Seite
[XML]<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Studenten</title>
</head>
<body>
<h1>Liste aller Studenten</h1>
<c:forEach var="student" items="${students}">
<fieldset>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<th>Id</th>
<td>${student.id}</td>
</tr>
<tr>
<th>Name</th>
<td>${student.name}</td>
</tr>
<tr>
<th>Stadt</th>
<td>${student.town}</td>
</tr>
</table>
</fieldset>
<p> </p>
</c:forEach>
</body>
</html>[/XML]
Der Controller
Auszug aus Student.java
Auszug aus dem Service
Auszug aus dem Dao
Hier meine Konfiguration
web.xml
[XML]<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="3.0" metadata-complete="true"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<display-name>webber</display-name>
<context-param>
<description>
Der Parameter für den ApplicationContext der fachlichen Logik
</description>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:META-INF/spring/context-web.xml</param-value>
</context-param>
<filter>
<description>Der Filter für das Encoding</description>
<filter-name>encoding-filter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<description>Der Parameter für das Encoding</description>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encoding-filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<description>
Der Listener für die Konfiguration des ApplicationContext
der fachlichen Logik
</description>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>[/XML]
context-web.xml
[XML]<?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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
Index of /schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
Index of /schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
Index of /schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<aop:aspectj-autoproxy proxy-target-class="true" />
<context:annotation-config />
<context:load-time-weaver aspectj-weaving="on" />
<import resource="classpath:/de/webber/application.xml" />
<import resource="classpath:/de/webber/services/studentservices.xml" />
<import resource="classpath:/META-INF/spring/db.xml" />
</beans>[/XML]
spring-servlet.xml
[XML]<?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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
Index of /schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
Index of /schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
Index of /schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<aop:aspectj-autoproxy proxy-target-class="true" />
<context:annotation-config />
<context:load-time-weaver aspectj-weaving="on" />
<import resource="classpath:/de/webber/application.xml" />
<import resource="classpath:/de/webber/services/studentservices.xml" />
<import resource="classpath:/META-INF/spring/db.xml" />
</beans>[/XML]
application.xml
[XML]<?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"
xsi:schemaLocation="
Index of /schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
Index of /schema/context
http://www.springframework.org/schema/context/spring-context.xsd
">
<context:component-scan base-package="de.webber" />
</beans>[/XML]
studentservices.xml
[XML]<?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"
xsi:schemaLocation="
Index of /schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
Index of /schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="de.webber.services" />
</beans>[/XML]
db.xml
[XML]<?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
="http://www.springframework.org/schema/p"
xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
Index of /schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
Index of /schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
Index of /schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<jdbc:embedded-database id="dataSource" type="HSQL">
<jdbc:script location="classpath:/META-INF/spring/init.sql" />
</jdbc:embedded-database>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
p:dataSource-ref="dataSource" p
ersistenceUnitName="webberPU">
<property name="persistenceXmlLocation" value="classpath*:META-INF/persistence.xml"/>
<property name="jpaVendorAdapter">
<bean p:generateDdl="true"
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
</property>
</bean>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"
p
roxyTargetClass="true" />
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
p:entityManagerFactory-ref="entityManagerFactory" />
<tx:annotation-driven proxy-target-class="true" />
</beans>[/XML]
Gruß,
Raphalon
Habe eine kleine Anwendung (siehe Anhang) mit Spring + Hibernate(JPA) auf Wildfly8 erstellt. Dabei möchte ich eine Liste von Studenten auf einer jsp-Seite anzeigen lassen (students.jsp). Allerdings erhalte ich einen Fehler java.lang.IllegalArgumentException: No query defined for that name [Student.findAll]. Warum? Am Dao / Service kann es eigentlich nicht liegen, denn - als Konsolenanwendung konfiguriert - läuft es.
Die jsp-Seite
[XML]<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Studenten</title>
</head>
<body>
<h1>Liste aller Studenten</h1>
<c:forEach var="student" items="${students}">
<fieldset>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<th>Id</th>
<td>${student.id}</td>
</tr>
<tr>
<th>Name</th>
<td>${student.name}</td>
</tr>
<tr>
<th>Stadt</th>
<td>${student.town}</td>
</tr>
</table>
</fieldset>
<p> </p>
</c:forEach>
</body>
</html>[/XML]
Der Controller
Java:
package de.webber.web.controllers;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import de.webber.domain.Student;
import de.webber.services.StudentService;
@Controller
public class StudentController {
@Autowired(required = true)
private StudentService studentService;
@RequestMapping("/student")
public String listStudents(Model model) {
List<Student> students = studentService.findAll();
model.addAttribute("students", students);
return "student";
}
}
Auszug aus Student.java
Java:
@Entity
@Table(schema = "students")
@NamedQueries(@NamedQuery(name = Student.FIND_ALL, query = Student.FIND_ALL_SQL))
public class Student {
public static final String FIND_ALL = "Student.findAll";
public static final String FIND_ALL_SQL = "Select s from Student s";
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "StudentSEQ")
@SequenceGenerator(name = "StudentSEQ", sequenceName = "StudentSEQ", schema = "students")
@Basic(optional = false)
private Long id;
@Basic(optional = false)
private String name;
@Basic(optional = false)
private String town;
Auszug aus dem Service
Java:
@Service("students")
@Transactional
public class StudentServiceImpl implements StudentService {
@Autowired(required = true)
private StudentDaoImpl studentDao;
@Override
@Transactional(propagation = Propagation.SUPPORTS)
public List<Student> findAll() {
return studentDao.findAll();
}
Auszug aus dem Dao
Java:
@Repository
public class StudentDaoImpl implements StudentDao {
@PersistenceContext
private EntityManager em;
@Override
public List<Student> findAll() {
return em.createNamedQuery(Student.FIND_ALL, Student.class)
.getResultList();
}
Hier meine Konfiguration
web.xml
[XML]<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="3.0" metadata-complete="true"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<display-name>webber</display-name>
<context-param>
<description>
Der Parameter für den ApplicationContext der fachlichen Logik
</description>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:META-INF/spring/context-web.xml</param-value>
</context-param>
<filter>
<description>Der Filter für das Encoding</description>
<filter-name>encoding-filter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<description>Der Parameter für das Encoding</description>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encoding-filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<description>
Der Listener für die Konfiguration des ApplicationContext
der fachlichen Logik
</description>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>[/XML]
context-web.xml
[XML]<?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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
Index of /schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
Index of /schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
Index of /schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<aop:aspectj-autoproxy proxy-target-class="true" />
<context:annotation-config />
<context:load-time-weaver aspectj-weaving="on" />
<import resource="classpath:/de/webber/application.xml" />
<import resource="classpath:/de/webber/services/studentservices.xml" />
<import resource="classpath:/META-INF/spring/db.xml" />
</beans>[/XML]
spring-servlet.xml
[XML]<?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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
Index of /schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
Index of /schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
Index of /schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<aop:aspectj-autoproxy proxy-target-class="true" />
<context:annotation-config />
<context:load-time-weaver aspectj-weaving="on" />
<import resource="classpath:/de/webber/application.xml" />
<import resource="classpath:/de/webber/services/studentservices.xml" />
<import resource="classpath:/META-INF/spring/db.xml" />
</beans>[/XML]
application.xml
[XML]<?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"
xsi:schemaLocation="
Index of /schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
Index of /schema/context
http://www.springframework.org/schema/context/spring-context.xsd
">
<context:component-scan base-package="de.webber" />
</beans>[/XML]
studentservices.xml
[XML]<?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"
xsi:schemaLocation="
Index of /schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
Index of /schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="de.webber.services" />
</beans>[/XML]
db.xml
[XML]<?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
xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
Index of /schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
Index of /schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
Index of /schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<jdbc:embedded-database id="dataSource" type="HSQL">
<jdbc:script location="classpath:/META-INF/spring/init.sql" />
</jdbc:embedded-database>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
p:dataSource-ref="dataSource" p
<property name="persistenceXmlLocation" value="classpath*:META-INF/persistence.xml"/>
<property name="jpaVendorAdapter">
<bean p:generateDdl="true"
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
</property>
</bean>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"
p
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
p:entityManagerFactory-ref="entityManagerFactory" />
<tx:annotation-driven proxy-target-class="true" />
</beans>[/XML]
Gruß,
Raphalon