我试图修改下面的代码三个小时。 我一直收到消息:
线程中的异常" main" java.lang.IllegalArgumentException:org.hibernate.hql.internal.ast.QuerySyntaxException:任务未映射[来自任务]
在JpaToDoList类中,显示警告 taskList = entityManager.createQuery(" from task")。getResultList(); 我没有,我怎么能修复项目nad有谁知道我在哪里可以找到错误?
Task.java
package test.spring.model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
package test.spring.model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table( name="task")
public class Task {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "id")
private int id;
@Column(name="firstname")
private String firstname;
@Column(name="lastname")
private String lastname;
public Task() {}
public Task(int id, String firstName, String lastName) {
this.id = id;
this.firstname = firstName;
this.lastname = lastName;
}
public String toString() {
return "Task#" + id + " dla " + firstname+" "+lastname;
}
public Task(int id) {
this.id = id;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
}
的persistence.xml
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="taskmanager" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>test.spring.model.Task</class>
</persistence-unit>
</persistence>
JPA:
package test.spring.service;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import test.spring.model.Task;
@Service
@Qualifier("jpa")
public class JpaToDoList implements ToDoListStrategy {
List<Task>taskList;
@PersistenceContext
private EntityManager entityManager;
public List<Task> createListTasks() {
taskList = (List<Task>) entityManager.createQuery("select e from Task e").getResultList();
return taskList;
}
}
在您修改之后,我得到下一个错误&#34;没有实体的默认构造函数:: test.spring.model.Task&#34;
以上代码包含修复程序。