Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
343 views
in Technique[技术] by (71.8m points)

struts2 - Hibernate exception found in calling buildsessionfactory method

I'm finding the exception :-[java.lang.NoSuchMethodError: org.hibernate.internal.CoreMessageLogger.debugf(Ljava/lang/String;I)V] while calling the buildsessionfactory method. For this exception I haven't been able to connect with the database(mysql). Here is my code:- Action file :- EmpAction.java:-

package techmyguru.actions;



import com.opensymphony.xwork2.ActionSupport;
//import com.opensymphony.xwork2.ModelDriven;
//import com.opensymphony.xwork2.Preparable;

public class EmpAction extends ActionSupport {
	//Employee emp;
	private int id;
	private String password;
	private String name;
	private String email;
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
    public String execute()
	{
		try{
			int i=EmpDao.register(this);
			if(i==1)
			{
			return "success";
			}
			else
			{
				return "error";
			}
		}
		catch(Throwable t)
		{
			t.toString();
			return "fail";
		}
	}  
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This is working code You can try it.

    private static SessionFactory sessionFactory;
    private static ServiceRegistry serviceRegistry;
    Configuration configuration = new Configuration();
    configuration.configure("hibernate.cfg.xml");

    serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
    sessionFactory = configuration.buildSessionFactory(serviceRegistry);
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    // process your business logic.
    session.getTransaction().commit();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...