| Home | JSP | EJB | JDBC | Java Servlets | WAP | Free JSP Hosting | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML | ||||
|
||||
|
|
||||
| Tutorial Categories: Ajax
| Articles
| JSP
| Bioinformatics
| Database
| Free
Books |
Hibernate
| J2EE
| J2ME
| Java
| JavaScript
| JDBC
| JMS
| Linux
| MS
Technology |
PHP
| RMI
| Web-Services
| Servlets
| Struts
| UML
|
|
||||||||||||||||||||||||||||||
|
Home | JSP | EJB | JDBC | Java Servlets | WAP | Free JSP Hosting | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs |
||||||||||||||||||||||||||||||
Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.
Copyright © 2007. All rights reserved.
Current Comments
5 comments so far (post your own) View All Comments Latest 10 Comments:good comments
Posted by arabinda on Tuesday, 08.7.07 @ 21:51pm | #22883
hi,
y it is not working
Posted by sabi on Saturday, 12.9.06 @ 18:18pm | #708
hi,
i want to delete some records from 1 table and then i have to insert new one.I write the HQL for this like the method below.in this i wrote delete first and then insert(look at last section DELETE and SAVE operations only).but when committed it tries to perform insert first so constraint violation happens and DB2 state err coming.can u give an example for delete and insert inside 1 transaction to 1 table.I want it soon .I stuck with that problem in my project..
shinoy
Posted by shinoy on Saturday, 12.9.06 @ 18:17pm | #707
hi,
i want to delete some records from 1 table and then i have to insert new one.I write the HQL for this like the method below.in this i wrote delete first and then insert(look at last section DELETE and SAVE operations only).but when committed it tries to perform insert first so constraint violation happens and DB2 state err coming.can u give an example for delete and insert inside 1 transaction to 1 table.I want it soon .I stuck with that problem in my project..
private void updateContact(CustomerContactForm customerContactForm,GDMSUserDTO roleUser)
{
Timestamp CurrentTS = new Timestamp(System.currentTimeMillis());
SessionFactory sf = null;
Session hibSession = null;
StringBuffer cusQuery=new StringBuffer();
StringBuffer cusQueryCmnt=new StringBuffer();
StringBuffer cusQueryChgLog=new StringBuffer();
StringBuffer cusQueryContDoc=new StringBuffer();
hibSession = HibernateUtil.getSessionFactory().openSession();
Transaction tx = hibSession.beginTransaction();
Long custContSkey=customerContactForm.getCustContSkey();//new Long(45);
try {
List custCont = new ArrayList();
cusQuery.append("from fit.gdms.schemadao.CustomerContact con ");
cusQuery.append("where con.custContSkey ="+custContSkey); //:custContSkey
custCont = hibSession.createQuery(new String(cusQuery)).list();
if (custCont.size()> 0)
{
CustomerContact custContact = (CustomerContact)custCont.get(0);
if(!(custContact.getCustContName()==customerContactForm.getContactName()))
{
custContact.setCustContName(customerContactForm.getContactName());
Customer customer=new Customer();
customer.setCustSkey(customerContactForm.getCustSkey());
custContact.setCustomer(customer);
Language language=new Language();
language.setLanguageCd(customerContactForm.getLanguageCd());
custContact.setLanguage(language);
ContactPosition contPosition=new ContactPosition();
contPosition.setContPosCd(customerContactForm.getPosition());//(contPosCd);
custContact.setCustContName(customerContactForm.getContactName());
custContact.setContactPosition(contPosition);
custContact.setContDept(customerContactForm.getDepartment());
custContact.setContEmail(customerContactForm.getEmail());
custContact.setContPhone1(customerContactForm.getPhone1());
custContact.setContPhone2(customerContactForm.getPhone2());
custContact.setContFax1(customerContactForm.getFax1());
custContact.setContFax2(customerContactForm.getFax2());
custContact.setCustConAddr1(customerContactForm.getLine1());
custContact.setCustConAddr2(customerContactForm.getLine2());
custContact.setCustConAddr3(customerContactForm.getLine3());
custContact.setCustConAddr4(customerContactForm.getPlaceCity());
custContact.setCustConAddr5(customerContactForm.getState());
custContact.setCustConAddr6(customerContactForm.getCountry());
custContact.setCustConAddr7(customerContactForm.getZipPostalCode());
if(("OTH").equalsIgnoreCase(customerContactForm.getPosition()))
{
custContact.setContPosDesc(customerContactForm.getPosDocdesc());
}
custContact.setLastUpdId(roleUser.getUserCNUM());
custContact.setLastUpdTs(CurrentTS);
hibSession.update(custContact);
}
List custContCmntList = new ArrayList();
cusQueryCmnt.append("from fit.gdms.schemadao.CustContCmnt cmnt ");
cusQueryCmnt.append("where cmnt.customerContact.custContSkey ="+custContSkey);//:custContSkey");
custContCmntList = hibSession.createQuery(new String(cusQueryCmnt)).list();
if (custContCmntList.size()> 0)
{
CustContCmnt custContCmnt = (CustContCmnt)custContCmntList.get(0);
custContCmnt.setCmntLogText(customerContactForm.getComments());
custContCmnt.setCustomerContact(custContact);//.setCustomerContact(custContact);
custContCmnt.setLastUpdId(roleUser.getUserCNUM());
custContCmnt.setLastUpdTs(CurrentTS);
hibSession.update(custContCmnt);
}
List custCntChgLogList = new ArrayList();
cusQueryChgLog.append("from fit.gdms.schemadao.CustCntChgLog cccl ");
cusQueryChgLog.append("where cccl.customerContact.custContSkey ="+custContSkey);//:custContSkey");
custCntChgLogList = hibSession.createQuery(new String(cusQueryChgLog)).list();
if (custCntChgLogList.size()> 0)
{
CustCntChgLog custCntChgLog = (CustCntChgLog)custCntChgLogList.get(0);
custCntChgLog.setCustomerContact(custContact);
custCntChgLog.setChgItem("CustomerContactName");
custCntChgLog.setLastUpdId(roleUser.getUserCNUM());
custCntChgLog.setLastUpdTs(CurrentTS);
custCntChgLog.setOldChgValue(custCntChgLog.getNewChgValue());
custCntChgLog.setNewChgValue(customerContactForm.getContactName());
hibSession.update(custCntChgLog);
}
List custContDocList = new ArrayList();
cusQueryContDoc.append("from fit.gdms.schemadao.CustContDoc ccd ");
cusQueryContDoc.append("where ccd.customerContact.custContSkey ="+custContSkey);//:custContSkey");
custContDocList = hibSession.createQuery(new String(cusQueryContDoc)).list();
if (custContDocList.size()> 0)
{
for(int i=0;i<custContDocList.size();i++)
{
CustContDoc custContDoc = (CustContDoc)custContDocList.get(i);
hibSession.delete(custContDoc);
}
}
if(customerContactForm.getContDoc()!=null)
{
for (int i = 0; i< customerContactForm.getContDoc().length ;i++)
{
String[] contDoc = customerContactForm.getContDoc();
String contDocCd = contDoc[i];
CustContDoc custContDoc = new CustContDoc();
ContactDocmt contDocmt = new ContactDocmt();
contDocmt.setContDocCd(contDocCd);
Language lang=new Language();
lang.setLanguageCd(customerContactForm.getLanguageCd());
if (("OTH").equalsIgnoreCase(contDocCd) )
{
custContDoc.setContDocDesc(customerContactForm.getContDocDesc());
}
custContDoc.setLanguage(lang);
custContDoc.setContactDocmt(contDocmt);
custContDoc.setCustomerContact(custContact);
custContDoc.setLastUpdId(roleUser.getUserCNUM());
custContDoc.setLastUpdTs(CurrentTS);
hibSession.save(custContDoc);
}
}
tx.commit();
//hibSession.flush();
hibSession.close();
}
}catch (HibernateException e) {
tx.rollback();
System.out.println("err "+e);
e.getStackTrace();
}catch (Exception e) {
e.printStackTrace();
} finally {
//hibSession.close();
}
return ;
}
Posted by shinoy v on Saturday, 12.9.06 @ 18:14pm | #705
A very good tutorial which is very simple to understand. thanks to roseindia.net..
Posted by SANTANU on Monday, 12.4.06 @ 20:18pm | #393