我在播放时使用了hibernate!框架。这是我的实体:
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import models.User;
import org.hibernate.annotations.DynamicUpdate;
import play.db.jpa.JPA;
import play.db.jpa.Transactional;
import play.libs.Json;
import javax.persistence.*;
import java.util.List;
@Entity
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
@DynamicUpdate(value=true)
@Table(name = "trees")
public class DecisionTree implements IModel{
...
}
这是我的persistence.xml
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
<persistence-unit name="defaultPersistenceUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<non-jta-data-source>DefaultDS</non-jta-data-source>
<class>models.User</class>
<class>models.role.Role</class>
<class>models.role.UserRole</class>
<class>models.role.RolePermission</class>
<class>models.ai.DecisionTree</class>
<class>models.ai.DecisionNode</class>
<class>models.ai.Link</class>
<class>models.ai.NodeContent</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
<!--property name="hibernate.show_sql" value="false" />
<property name="hibernate.format_sql" value="false" /-->
</properties>
</persistence-unit>
</persistence>
这是我执行的代码:
public static List<DecisionTree>findAll(){
TypedQuery<DecisionTree> query = JPA.em().createQuery("SELECT n FROM DecisionTree n", DecisionTree.class);
return query.getResultList();
}
这就是我得到的:
[IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: DecisionTree is not mapped [SELECT n FROM DecisionTree n]]
In /Users/saksham/workspace/sde/app/models/ai/DecisionTree.java:96
93 }
94
95 public static List<DecisionTree>findAll(){
96 TypedQuery<DecisionTree> query = JPA.em().createQuery("SELECT n FROM DecisionTree n", DecisionTree.class);
98 return query.getResultList();
99 }
我在这里可能缺少的任何线索?存在Mysql表,所有表列也是如此。