0

I'm learning Spring Boot,I want to query data by hibernate,

the below is structure: enter image description here

and SpringExampleApplication class is:

@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);
     }
}
}

User class is:

@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;
}
}   

then the expetion throws when I run the test case:

 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= ? ]

thanks for help.

eason
  • 13
  • 3
  • This link might help http://stackoverflow.com/questions/14446048/hibernate-table-not-mapped-error – Ashay Patil Apr 14 '16 at 05:57
  • The anwser is not what I want.I use hql like this: List user=this.sessionFactory.getCurrentSession().createQuery("from User where id= ? ").setParameter(0, 1).list(); – eason Apr 14 '16 at 06:24
  • Could you post the contents of the _application-db.xml_ file? For your example I don't think you would need to perform any app context configuration. Anyway, to have a quick working project I would advise you to use the [spring boot initializer](http://start.spring.io/) – Cèsar Apr 15 '16 at 06:42

0 Answers0