Hi
I am an newbie to hibernate annotations.
Initial SessionFactory creation failed.org.hibernate.MappingNotFoundException: resource: course_new not found
course_new.java
Code:
package data;
import java.io.Serializable;
import java.util.Set;
import java.util.UUID;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Version;
@Entity
@Table(name="course")
public class course_new implements Serializable {
String id = UUID.randomUUID().toString();
@Id
@Column(name = "course_id", updatable = true, nullable = false, unique = true)
private long courseId;
@Column(name = "course_name", updatable = true, nullable = false, length = 255)
private String courseName;
public long getCourseId() {
return this.courseId;
}
public void setCourseId(long courseId) {
this.courseId = courseId;
}
public String getCourseName() {
return this.courseName;
}
public void setCourseName(String courseName) {
this.courseName = courseName;
}
}
HibernateUtil.java
Code:
package data;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
public class HibernateUtil
{
private static final SessionFactory sessionFactory;
static
{
try
{
AnnotationConfiguration config = new AnnotationConfiguration();
config.setProperty("hibernate.dialect","org.hibernate.dialect.MySQLDialect");
config.setProperty("hibernate.connection.driver_class","com.mysql.jdbc.Driver");
config.setProperty("hibernate.connection.url","jdbc:mysql://localhost:3306/mydatabase");
config.setProperty("hibernate.connection.username","root");
config.setProperty("hibernate.connection.password","root");
config.setProperty("hibernate.connection.pool_size","1");
config.setProperty("hibernate.connection.autocommit","true");
config.setProperty("hibernate.cache.provider_class","org.hibernate.cache.NoCacheProvider");
config.setProperty("hibernate.hbm2ddl.auto","create-drop");
config.setProperty("hibernate.show_sql","true");
config.setProperty("hibernate.transaction.factory_class","org.hibernate.transaction.JDBCTransactionFactory");
config.setProperty("hibernate.current_session_context_class","thread");
config.addResource("course_new");
sessionFactory = config.buildSessionFactory();
}
catch (Throwable ex)
{
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory()
{
return sessionFactory;
}
}
I added the below line in HibernateUtil.java
config.addResource("course_new");
rather than in xml file like
<!-- Mapping files -->
<mapping resource="course_new.hbm.xml" />
which I am not mapping using an XML file, doing it directly from HibernateUtil.java
but getting exception.
Folder structure is
NetBeansProjects\hibernate\src\data ------->all the source files
NetBeansProjects\hibernate\build\classes\data------->all the class files.
tried using slash and dot while class name in specifying config.addResourse(course_new), but of no use.
thanks
Mukunda