我不明白为什么会收到此错误:
//EX[2,1,["java.lang.IllegalArgumentException/1755012560",
"An exception occurred while creating a query in EntityManager:
\r\nException Description: Problem compiling [SELECT u FROM Users u]. \n[14, 19]
The abstract schema type \x27Users\x27 is unknown."],0,7]
看起来所有配置都是正确的,但仍然出现此错误。请帮忙。我的配置如下:
MySql 表:
CREATE TABLE `users` (
`USER_ID` int(10) unsigned NOT NULL AUTO_INCREMENT,
`USERNAME` varchar(45) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`PASSWORD` varchar(45) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`ENABLED` tinyint(1) NOT NULL,
`firstname` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
`lastname` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
`email` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`USER_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8
实体:
package com.val.dogovora.entity;
import javax.persistence.*;
import java.io.Serializable;
@Entity
public class Users implements Serializable {
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
private int USER_ID;
private String USERNAME;
private String PASSWORD;
private int ENABLED;
private String firstname;
private String lastname;
private String email;
public Users() {
}
public Users(String USERNAME, String PASSWORD, int ENABLED, String firstname, String lastname, String email) {
this.USERNAME = USERNAME;
this.PASSWORD = PASSWORD;
this.ENABLED = ENABLED;
this.firstname = firstname;
this.lastname = lastname;
this.email = email;
}
Getters and Setters...
}
持久性.xml
<class>com.val.dogovora.entity.Users</class>
代码:
EntityManagerFactory emf = Persistence.createEntityManagerFactory("DogovoraPool");
EntityManager em = emf.createEntityManager();
TypedQuery<Users> query = em.createQuery("SELECT u FROM Users u", Users.class);