Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
357 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 Reply

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();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...