I am running simple hibernate program ,but it is giving me error mention in the title My hibernate.cfg.xml is as follows:-
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/myhiber</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">rishabh123#</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="hibernate.show_sql">true</property>
<mapping class="com.tut.ProjectwithMaven.Student"/>
</session-factory>
</hibernate-configuration>
My code is as follows:-
public class App
{
public static void main( String[] args )throws Exception
{
System.out.println( "Hello World!" );
// Configuration cfg=new Configuration();
try {
new Configuration().configure("hibernate.cfg.xml");
} catch (HibernateException e) {
// TODO Auto-generated catch block
try
{
throw (Throwable)e;
}
catch(Throwable ex)
{
ex.printStackTrace();
}
}
System.out.println("AAge");
SessionFactory factory=new Configuration().buildSessionFactory();
Student st=new Student();
st.setId(101);
st.setName("Rishabh");
st.setCity("Bangalore");
Session session=factory.openSession();
session.beginTransaction();
session.save(st);
session.getTransaction().commit();
session.close();
Please help in resolving this issue, i have checked pom.xml ,it seems to be right,but still giving same error again and again
Well, you are not using this configuration file. See the line you posted:
It should be