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
 
 
Hot Web Programming Job

 

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


 

Java Tutorials

Core Java
JSP
Servlet
JDBC
Hibernate
Struts 1
Struts 2
JSF
Spring
J2EE
J2ME
Web Services
Ajax
Dojo
MySQL
Latest Comments
Good one ...But Mi
ATA-S2 Ip configur
Nice article
Create Exe File
i want struts2 IDE
  All Comments...
 

 

 
Struts Tutorials
*Stuts TOC
*Apache Struts Introduction
* Struts Controller
* Struts Action Class
* Struts ActionFrom Class
* Using Struts HTML Tags
*Struts Validator Framework    
*Client Side Address Validation    
*Struts Tiles
*tiles-defs.xml
*Struts DynaActionForm
*Struts File Upload
*Struts DataSource
*AGGREGATING ACTIONS
*Internationalization
Struts Resources
*Struts Books
*Struts Articles
*Struts Frameworks
*Struts IDE
*Struts Alternative
*Struts Links
*Struts Presentations
*Struts Projects
*Struts Software
*Struts Reference
*Struts Resources
*Other Struts Tutorial
Visit Forum! Post Questions!
Jobs At RoseIndia.net!

Have tutorials?
Add your tutorial to our Java Resource and get tons of hits.

We offer free hosting for your tutorials. and exposure for thousands of readers. drop a mail
roseindia_net@yahoo.com
 
   

 
Join For Newsletter

Powered by groups.yahoo.com
Visit Group! Post Questions!

Hibernate Hibernatequerylanguagehql

User Comments
Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl
  Blink   Furl   Simpy   Y! MyWeb 

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

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

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Back to Tutorial

 

  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2007. All rights reserved.