私はSpringとHibernateが初めてです。データベースからすべてのデータを挿入および取得しようとしています。mySql db にデータを挿入しましたが、データベースからすべてのデータを取得しようとしていますが、例外が発生しています。問題を解決するために私ができること。
Jul 04, 2012 10:46:58 AM org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 1064, SQLState: 42000
Jul 04, 2012 10:46:58 AM org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') as emp1_0_, employee0_.address as address0_, employee0_.emp_email as emp3_0_, ' at line 1
Hibernate: select employee0_.emp_id) as emp1_0_, employee0_.address as address0_, employee0_.emp_email as emp3_0_, employee0_.manager_id as manager4_0_, employee0_.emp_name as emp5_0_ from employee employee0_
org.hibernate.exception.SQLGrammarException: could not execute query
休止状態のコードは
public void getAll() {
Session session = HibernateUtil.getSessionFactory().openSession();
Transaction transaction = null;
try {
transaction = (Transaction) session.beginTransaction();
List employees = session.createQuery("from Employee").list();
for (Iterator iterator = employees.iterator(); iterator.hasNext();) {
Employee employee = (Employee) iterator.next();
System.out.println(employee.getName());
}
transaction.commit();
} catch (HibernateException e) {
transaction.rollback();
} finally {
session.close();
}
}
従業員.java
@Entity
@Table(name="employee")
public class Employee {
private int id;
private String name;
private String email;
private String address;
private int managerId;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="emp_id)")
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Column(name="emp_name")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Column(name="emp_email")
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
@Column(name="address")
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
@Column(name="manager_id")
public int getManagerId() {
return managerId;
}
public void setManagerId(int managerId) {
this.managerId = managerId;
}
}