我正在编写一个 Spring Boot + Hibernate JPA 应用程序,我的休眠代码不起作用,下面是详细信息
实体类:
@Entity
@Table(name="user")
public class UserBean {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "idUser")
String id;
@Column(name = "UserName")
String name;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
服务/DAO:
@Transactional
@Repository
public class SpringBootService {
@PersistenceContext
private EntityManager entityManager;
public boolean userLogin(UserBean bean) {
String hql = "FROM UserBean WHERE id = ? ";
int count = entityManager.createQuery(hql).setParameter(0, bean.getId())
.getResultList().size();
return count > 0 ? true : false;
}
}
下面是我的桌子
我收到以下异常
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'userbean0_.id_user' in 'field list'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_162]
我已经检查了实体类中的表名和列名都是正确的,这是一个简单的映射,我也不涉及第二个表。