0
votes

I am new to Hibernate. Recently, I was trying simple example to connect my UI with Database using Spring and Hibernate.

I am able to successfully call a method to fetch the data through my controller, service etc using REST. But I am encountering below error,whenever I run the application. Here "Feedback" is the name of Table in Database as well as the same name of my Pojo Java class.

Note : Giving different names to table and Java class also results in same error.

org.springframework.orm.hibernate3.HibernateQueryException: Feedback is not mapped [from Feedback]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: Feedback is not mapped [from Feedback]

Java Pojo:-

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name="Feedback")
public class Feedback {
    private int id;
    private String title;
    private String content;
    private String name;

    @Id
    @GeneratedValue
    @Column(name="id")
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }

    @Column(name="title", nullable=false)
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }

    @Column(name="content", nullable=false)
    public String getContent() {
        return content;
    }
    public void setContent(String content) {
        this.content = content;
    }

    @Column(name="name", nullable=false)
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    @Override
    public String toString() {
        return "Feedback [id=" + id + ", title=" + title + ", content="
                + content + ", name=" + name + "]";
    }
}

FeedbackDAO :-

@Repository
public class FeedbackDAO implements IFeedbackDAO {

    private HibernateTemplate hibernateTemplate;

    public HibernateTemplate getHibernateTemplate() {
        return hibernateTemplate;
    }

    @Autowired
    public void setSessionFactory(SessionFactory sessionFactory) {
        hibernateTemplate = new HibernateTemplate(sessionFactory);
    }

    @SuppressWarnings("unchecked")
    public List<Feedback> getFeedbackList() {

       // This line causes that error.
        return hibernateTemplate.find("from Feedback");

    }
       ...
       ...
}

Configuration made in db-config.xml

 <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory"><ref local="sessionFactory"/></property>
    </bean>

What could be causing this ?

Do am I missing something here ?

Thanks

1
If you require any more details, please let me know.Daemon

1 Answers

2
votes

You might have missed a thing in sessionFactory definition.

<bean id="sessionFactory" ...>
    ...
    <property name="annotatedClasses">
        <list>
            <value><java package name here>.Feedback</value>
        </list>
    </property>
    ...
</bean>