Error Stack:
Code:
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
org.hibernate.HibernateException: Not able to obtain connection
at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:117)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:93)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:86)
at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:169)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2047)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2426)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:51)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:243)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:227)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:296)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:877)
at revised.Main.main(Main.java:30)
IDE :Exadel studio pro 2.5 & MySQL 4
Database Schema
1.Logindetails(userid,password).
2.Psersonaldetails(userid,name)-'userid' is a foregien key ref .of 'logindetails'.
Mapping file 'logindetails':Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="revised">
<class name="Logindetails" table="logindetails" optimistic-lock="none">
<id name="userId" type="string" unsaved-value="null" column="UserId" length="40">
<generator class="hilo"/>
</id>
<property name="password" type="string" column="Password" length="40"/>
<one-to-one name="personaldetails" entity-name="revised.Personaldetails" cascade="save-update" foreign-key="personaldetails_ibfk_1" property-ref="userIdPersonal"/>
</class>
</hibernate-mapping>
Mapping file personaldetailsCode:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="revised">
<class name="Personaldetails" table="personaldetails" optimistic-lock="none">
<id name="uniq" type="integer" unsaved-value="null" column="uniq">
<generator class="assigned"/>
</id>
<property name="name" type="string" column="Name" length="40"/>
<many-to-one name="userIdPersonal" entity-name="revised.Logindetails" cascade="save-update" foreign-key="personaldetails_ibfk_1">
<column name="UserId_Personal" unique="true" index="IDX_personalDetails1" length="40"/>
</many-to-one>
</class>
</hibernate-mapping>
My Main Class file:Code:
package revised;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.Transaction;
import revised.Personaldetails;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Session session=null;
try
{
Configuration cfg=new Configuration();
cfg.configure();
SessionFactory factory = cfg.buildSessionFactory();
session=factory.openSession();
Transaction tx=session.beginTransaction();
Personaldetails ps=new Personaldetails();
ps.setUniq(new Integer(10));
ps.setUserIdPersonal(ps.getUserIdPersonal());
ps.setName("deva");
tx.commit();
session.save(ps);
session.flush();
session.close();
System.out.println("Completed");
}
catch(Exception e)
{
e.printStackTrace(System.out);
}
}
}