I am pretty new at Hibernate and I got some code working without much effort but wanted to know if this is the best way to go about this.
I have a table where I store issues for a help desk system. I have a JavaBean and the mapping xml file for this table. Part of the issue number I create contains the Auto Incremented ID number from the issue table. So after I insert the new record I get the ID and create the issue number, then I update that row with the new ticket number. Here is the code I am using to do this:
Code:
//Get the Session
Session ses = HibernateUtil.currentSession();
//Create a transaction
Transaction tx = ses.beginTransaction();
//Insert new Record
ses.save(callBean);
//Get current Date
java.util.Date date = new java.util.Date();
//Format the date
SimpleDateFormat sdf = new SimpleDateFormat("yyMMdd");
//Generate Issue Number
String ticket = techid + sdf.format(date).toString() + String.valueOf(callBean.getId());
//Set the Issue Number in the JavaBean
callBean.setTicket(ticket);
//Update the record with the new Issue Number
ses.saveOrUpdate(callBean);
//Commit the transaction
tx.commit();
//Close the session
HibernateUtil.closeSession();
This works, I just want to make sure what I am doing is not a "work around" way but the proper way of doing things.
Thanks for looking at this.