0

我不明白为什么会收到此错误:

//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);
4

1 回答 1

0

我想我找到了错误的原因。在我将我的项目从 Eclipse 转换为 Intellij Idea 之前。该文件夹my_project_name/war/web-if/classes保留旧文件。我删除了这个文件夹,现在我的项目可以正常工作了。但我不明白,如果 Intellij Idea 有自己的文件夹,为什么还要使用这些旧类my_project_name/out

于 2013-09-27T07:15:59.707 回答