Reputation: 3
The method addAnnotatedClass(Class) is undefined for the type Configuration
I am trying to insert data into data base using Hibernate in my Dynamic web project . Annotations are used instead of XML file. But i am getting a compilation error "The method addAnnotatedClass(Class) is undefined for the type Configuration" .How will i solve it ?
package pak;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class MainClass {
public static void main(String[] args) {
// TODO Auto-generated method stub
SessionFactory factory= new Configuration().configure("hibernate.cfg.xml").addAnnotatedClass(demo.class).buildSessionFactory();
Session session=factory.getCurrentSession();
try{
demo obj=new demo("name1","name2","name3");
session.beginTransaction();
session.save(obj);
session.getTransaction().commit();
}finally{
factory.close();
}
}
}
i want to know that, what is the cause compilation error "The method addAnnotatedClass(Class) is undefined for the type Configuration" and how to solve it
Upvotes: 0
Views: 911
Reputation: 138
Most probably you have forgotten to Annotate the demo class that you want to import there:
You should declare Annotations before you use that class.
Upvotes: 0