Hi Parag, Thanks for your help. I am posting my entire program for your help. Please try if you can resolve the gotcha...!JAVA invocation code:Code:
/
/
package com.wipro;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class Main {
/
*@param args*
/
public static void main(String[] args) {
// TODO Auto-generated method stub
Account account = new Account("Akshay");
Configuration cfg;
try {
cfg = new Configuration().addClass(Account.class);
SessionFactory sessionFactory = cfg.buildSessionFactory();
Session session = sessionFactory.openSession();
session.save(account);
session.flush();
session.close();
} catch (MappingException e) {
e.printStackTrace();
} catch (HibernateException e) {
e.printStackTrace();
}
}
}
my mapping file (Account.hbm.xml):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>
<class name="com.wipro.Account" table="account">
<id name="id" type="int" unsaved-value="null">
<column name="id" sql-type="int" not-null="true"/>
<generator class="assigned"/>
</id>
<property name="name">
<column name="name"/>
</property>
</class>
</hibernate-mapping>
my Configuration file (hibernate.config.xml):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>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/hibernatetutorial</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">akshay</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="show_sql">true</property>
<mapping resource="Account.hbm.xml"/>
</session-factory>
</hibernate-configuration>
my JavaBean (Account.java):.
Code:
/**
*
*/
package com.wipro;
import java.io.Serializable;
/**
* @author admin
*
*/
public class Account implements Serializable {
/**
*
*/
private static final long serialVersionUID = 2936147874996596000L;
private int id;
private String name;
/**
*
*/
public Account() {
}
public Account(String name, int id) {
this.name = name;
this.id = id;
}
/**
* @return the id
*/
public int getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(int id) {
this.id = id;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
}
my Table(account) description from MySQL:Code:
mysql> use hibernate_db;
Database changed
mysql> desc account;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int(11) | NO | PRI | NULL | |
| name | varchar(10) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.16 sec)
mysql>