Reputation: 11
I am learning hibernate, I have added all the required jars, but still am getting a compiler error saying
Configuration.configure cannot be resolved to a type.
Anyone have idea how to resolve this?
package org.ramya.hibernate;
import org.hibernate.cfg.Configuration;
import org.hibernate.SessionFactory;
import org.ramya.dto.UserDetails;
public class HibernateTest {
public static void main (String args[])
{
UserDetails user = new UserDetails();
user.setUserId(1);
user.setUserName("First user");
SessionFactory sessionFactory = new Configuration.configure().buildSessionFactory();
Session session = sessionFactory.openSession();
}
}
Upvotes: 1
Views: 191
Reputation: 332
Try to use This,
SessionFactory sf;
ServiceRegistry sr;
Configuration cfg=new Configuration().configure();
sr=new StandardServiceRegistryBuilder().applySettings(cfg.getProperties()).build();
sf=cfg.buildSessionFactory(sr);
Instead of ,
SessionFactory sessionFactory = new Configuration.configure().buildSessionFactory();
Since "buildSessionFactory()" has been deprecated over hibernate 3.5
And try to use latest version of hibernate as much as possible.
Please check this link for Details:- Deprecated Buildsessionfactory
Upvotes: 0
Reputation: 4154
You missed the parentheses () when instantiating the Configuration
object.
It should be:
new Configuration().configure()
Upvotes: 2