Hibernate Query Language – HQL

Hibernate Query Language – HQL  :

Description about HQL :-

  • HQL is the Object Oriented query language for Hibernate Framework.
  • HQL is a case-sensitive.
  • HQL with a simple and easy-to-use language.
    • While SQL use “SELECT * FROM USERS” to fetch all records in USERS table, But
    • for HQL we use “FROM USERS” .

1.) HQL Insert Query Language.

  • HQL also support INSERT INTO – example:
  • In HQL, only the INSERT INTO … SELECT … is supported; there is no INSERT INTO … VALUES. HQL only support insert from another table.
    • Query query = session.createQuery(“INSERT into USERS(userId, username)” + “SELECT bk.userId,bk.username FROM  BK_USERS bk“);

2.) HQL Update Query Language.

  • Example of HQL update query
 Transaction trans =session.beginTransaction();  
    Query query=session.createQuery("update Patient set PatientName=:pname where id=:pid");  
    query.setParameter("pname","franko Nando");  
    query.setParameter("pid",01);  
      
    int status=query.executeUpdate();  
    System.out.println(status);  
    trans.commit();

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s