Hi all,
I'm new to Hibernate & just started doing my 1st project using Hibernate.
I'm using the following jar files for my project
commons-collections-3.1.jar
commons-logging-1.1.1.jar
ejb3-persistence.jar
hibernate3.jar
hibernate-annotations-3.5.1-Final.jar
log4j-1.2.16.jar
mysql-connector-java-5.1.14-bin.jar
dom4j-1.6.1.jar
slf4j-api-1.6.1.jar
slf4j-log4j12-1.6.1.jar
hibernate-jpa-2.0-api-1.0.0.Final.jar
javassist-3.12.0.GA.jar
jta-1.1.jarWhen I create a simple JAVA project with following classes & run my example, it works fine.
Code:
package com.cmgt.db.util;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import com.cmgt.db.beans.User;
public class DBUtility {
private static DBUtility instance = null;
private Configuration configuration = null;
private SessionFactory factory = null;
private Session session = null;
private DBUtility(){
configuration = new Configuration();
// Add all BEAN classes here
configuration.addAnnotatedClass(User.class);
configuration.configure("hibernate.cfg.xml");
// new SchemaExport(configuration).create(true, true);
factory = configuration.buildSessionFactory();
session = factory.getCurrentSession();
}
public static DBUtility getInstance(){
if(instance == null){
instance = new DBUtility();
}
return instance;
}
public Session getSession() {
return session;
}
}
Code:
package com.cmgt.db.beans;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
@Entity
@Table(name="USER")
public class User {
private int userId; // ID of the user
private String userName; // Username of the user
private String password; // Password of the user
private int userLevel; // User level (see under "User levels" @ MiscUtility.java)
// -------------------- GETTERS -------------------- //
@Id
@Column(name="ID")
@TableGenerator(name = "userid", table = "tbluserid", pkColumnName = "userid", pkColumnValue = "uservalue",
allocationSize = 1)
@GeneratedValue(strategy = GenerationType.TABLE, generator = "userid")
public int getUserId() {
return userId;
}
@Column(name="USERNAME")
public String getUserName() {
return userName;
}
@Column(name="PASSWORD")
public String getPassword() {
return password;
}
@Column(name="LEVEL")
public int getUserLevel() {
return userLevel;
}
// -------------------- SETTERS -------------------- //
public void setUserId(int userId) {
this.userId = userId;
}
public void setUserName(String userName) {
this.userName = userName;
}
public void setPassword(String password) {
this.password = password;
}
public void setUserLevel(int userLevel) {
this.userLevel = userLevel;
}
}
But when I try to do the same in my WEB project, it gives me the following exception.
Dec 16, 2010 2:16:02 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet Transport Cost Management Application threw exception
java.lang.NoSuchMethodError: org.hibernate.cfg.AnnotationBinder.bindDefaults(Lorg/hibernate/cfg/Mappings;)V
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1360)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1826) at com.cmgt.db.util.DBUtility.<init>(DBUtility.java:28)
at com.cmgt.db.util.DBUtility.getInstance(DBUtility.java:35)
at com.cmgt.ui.login.Login.getUserLevel(Login.java:88)
at com.cmgt.ui.login.Login.onLogin(Login.java:41)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:487)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:161)
at com.vaadin.ui.AbstractComponent.fireEvent(AbstractComponent.java:1154)
at com.vaadin.ui.LoginForm$2.handleParameters(LoginForm.java:100)
at com.vaadin.ui.Window.handleParameters(Window.java:499)
at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(AbstractApplicationServlet.java:503)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
Can someone please tell me what's wrong here?
Any help is greatly appreciated.
Thanks in advance,
Asela.