我正在学习Spring Boot,我想通过hibernate查询数据,
以下是结构: enter image description here
和SpringExampleApplication类是:
@SpringBootApplication
@ImportResource("classpath:application-db.xml")
public class SpringExampleApplication {
public static void main(String[] args) {
ApplicationContext ctx = SpringApplication.run(SpringExampleApplication.class, args);
System.out.println("Let's inspect the beans provided by Spring Boot:");
String[] beanNames = ctx.getBeanDefinitionNames();
Arrays.sort(beanNames);
for (String beanName : beanNames) {
System.out.println(beanName);
}
}
}
用户类是:
@Entity
@Table(name="tf_f_user")
public class User {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private long id;
@Column(name="name",length=1024)
private String name;
@Column(name="address")
private String address;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}
然后在我运行测试用例时抛出了预算:
org.springframework.orm.hibernate4.HibernateQueryException: User is not mapped [from User where id= ? ]; nested exception is org.hibernate.hql.internal.ast.QuerySyntaxException: User is not mapped [from User where id= ? ]
感谢您的帮助。