I am having difficulty running sample code from
Hibernate Made Easy by Cameron McKenzie.
Tools / Libraries:
(1) Eclipse 3.5
(2) MySQL 5
(3) Hibernate 3.3.2.GA
(4) Hibernate Annotations 3.4.0.GA
Wrote a simple User class (located under /examscam/src):
Code:
package com.examscam.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import org.hibernate.cfg.AnnotationConfiguration;
@Entity
public class User {
private long id;
private String password;
@Id
@GeneratedValue
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
Wrote a TestApp (containing main() method - located under /examscam/src):
Code:
package com.examscam.app;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import com.examscam.model.User;
public class TestApp {
public static void main(String[] args) {
AnnotationConfiguration config = new AnnotationConfiguration();
config.addAnnotatedClass(User.class);
config.configure();
new SchemaExport(config).create(true, true);
}
}
hibernate.cfg.xml (located under /examscam/src):
Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/examscam</property>
<property name="connection.username">root</property>
<property name="connection.password"></property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">2</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<!-- Enable Hibernate's current session context -->
<property name="current_session_context_class">org.hibernate.context.ManagedSessionContext</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
</session-factory>
</hibernate-configuration>
Eclipse Build Path:
ant-contrib-1.0b2.jar, ant-junit-1.6.5.jar, antlr-2.7.6.jar, asm-attrs.jar, asm.jar, c3p0-0.9.0.jar, cglib-2.1.3.jar, commons-collections-2.1.1.jar, commons-collections-3.1.jar, commons-logging-1.0.4.jar, dom4j-1.6.1.jar, ejb3-persistence.jar, hibernate-annotations.jar, hibernate-commons-annotations.jar, hibernate-tools.jar, javassist-3.9.0.GA.jar, jta-1.1.jar, junit-3.8.1.jar, mysql-connector-java-5.1.7-bin.jar, slf4j-api-1.5.8.jar
Problem:
Eclipse states there's a problem starting in User.java, line number 12:
Code:
config.addAnnotatedClass(User.class);
"The type org.hibernate.MappingException cannot be resolved. It is indirectly referenced from required .class files"
"The project was not built since its build path is incomplete. Cannot find the class file for org.hibernate.MappingException. Fix the build path then try building this project examscam"
Question(s):
(1) What am I possibly doing wrong?
(2) Which jar file does org.hibernate.MappingException belong in?
(3) Am I placing the config file in the right place (right under /examscam/src)?