"users"테이블에서 모든 사용자 목록을 얻으려고하는데 다음 오류가 발생합니다.
org.hibernate.hql.internal.ast.QuerySyntaxException: users is not mapped [from users]
org.hibernate.hql.internal.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:180)
org.hibernate.hql.internal.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:110)
org.hibernate.hql.internal.ast.tree.FromClause.addFromElement(FromClause.java:93)
이것은 사용자를 추가 / 가져 오기 위해 작성한 코드입니다.
public List<User> getUsers() {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
List<User> result = (List<User>) session.createQuery("from users").list();
session.getTransaction().commit();
return result;
}
public void addUser(User user) {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
session.save(user);
session.getTransaction().commit();
}
public void addUser(List<User> users) {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
for (User user : users) {
session.save(user);
}
session.getTransaction().commit();
}
사용자 추가가 작동하지만 getUsers 기능을 사용할 때 이러한 오류가 발생합니다.
이것은 내 최대 절전 모드 구성 파일입니다.
<hibernate-configuration>
<session-factory>
<property name="connection.url">jdbc:mysql://localhost:3306/test</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.default_schema">test</property>
<property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="hbm2ddl.auto">create-drop</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<property name="current_session_context_class">thread</property>
<!-- Mapping files will go here.... -->
<mapping class="model.Company" />
<mapping class="model.Conference" />
<mapping class="model.ConferencesParticipants" />
<mapping class="model.ConferenceParticipantStatus" />
<mapping class="model.ConferencesUsers" />
<mapping class="model.Location" />
<mapping class="model.User" />
</session-factory>
그리고 이것은 내 사용자 클래스입니다.
@Entity
@Table( name = "Users" )
public class User implements Serializable{
private long userID;
private int pasportID;
private Company company;
private String name;
private String email;
private String phone1;
private String phone2;
private String password; //may be null/empty , will be kept hashed
private boolean isAdmin;
private Date lastLogin;
User() {} //not public on purpose!
public User(int countryID, Company company, String name, String email,
String phone1, String phone2, String password, boolean isAdmin) {
this.pasportID = countryID;
this.company = company;
this.name = name;
this.email = email;
this.phone1 = phone1;
this.phone2 = phone2;
this.password = password;
this.isAdmin = isAdmin;
}
@Id
@GeneratedValue(generator="increment")
@GenericGenerator(name="increment", strategy = "increment")
public long getUserID() {
return userID;
}
public void setUserID(long userID) {
this.userID = userID;
}
...
}
이 오류가 발생하는 이유는 무엇입니까?