Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
Mapping documents:
<class name="com.ams.dao.general.GnlDepartment"
table="gnldepartment">
<id name="departmentid" column="department_id"
type="java.lang.Integer">
<generator class="increment" />
</id>
<property name="departmentname" column="department_name"
type="java.lang.String" />
<property name="departmentkey" column="department_key"
type="java.lang.String" />
<property name="departmentcode" column="department_code"
type="java.lang.String" />
<property name="comments" column="comments"
type="java.lang.String" />
</class>
Code between sessionFactory.openSession() and session.close():
public static void insert(Object pobject) {
Session session = lSessionFactory.getCurrentSession();
try {
Transaction tx = session.beginTransaction();
session.save(pobject);
session.flush();
tx.commit();
} catch (HibernateException e) {
log.error("Argh ! Error occurred while creating object " + pobject
+ ": " + e);
} finally {
if (session != null && session.isOpen()) {
try {
session.close();
} catch (HibernateException e) {
log.error("Ouch ! Error occurred while closing session: "
+ e);
}
}
}
}
}
Full stack trace of any exception that occurs:
Name and version of the database you are using: Mysql 5.0
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
Problems with Session and transaction handling?
I am facing a problem that i need the inserted record primary key value where as i need it for displaying it.
Here the department id is the primary key value which is auto generated using hibernate.
I need that primary key value when i insert a record in a single step. please help me.