Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the common methods of Sessin interface in Hibernate

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail what are the common methods of Sessin interface in Hibernate. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

Common methods of Hibernate Sessin interface-- updata () and merge () methods generate SQL UPDATE

This method calls the load () method of Session, loads the Customer object, and then modifies the properties of the Customer object.

Session = HibernateUtil.currentSession (); tx = session.beginTransaction (); Book oneBook= (Book) session.load (Book.class,bookID); oneBook.setBookName ("Java application development" .getBytes ("gb2312"), "ISO8859-1")); oneBook.setBookKind ('1'); oneBook.setBookPrice (10.4f); tx.commit ()

Common methods of Hibernate Sessin Interface-- load and get methods

The load and get methods of session load an object from the database based on the given OID, the load method throws a notFoundException exception when no object is found, and the get method returns null

The objects returned by get and load and other query methods are in the cache of session. After the properties of the objects are modified, when session cleans the cache, the database is updated based on the properties of the persisted objects.

Used to retrieve objects in the database, the load () and get () methods load a persistent object according to the given OID

Public Iterator getAllCourses () throws HibernateException {String queryString = "select courses from Course as courses"; beginTransaction (); Query query = session.createQuery (queryString); Iterator it= query.iterate (); return it;} / * * makes a fuzzy lookup by the name of course and returns the Iterator that contains the Course persistent object. * / public Iterator getSomeCourse (String name) throws HibernateException {String queryString = "select c from Course as c where c.name like: name"; beginTransaction (); Query query = session.createQuery (queryString); query.setString ("name", "%" + name+ "%"); Iterator it= query.iterate (); return it;}

The common method of Hibernate Sessin interface-- delete () method generates SQL DELETE

Because the corresponding record of the object is deleted from the database, a delete statement is planned to be executed if the entry and exit is the persistent object session.

If the parameter in and out is a free object, first make it a persistent object, and then plan to execute a delete statement. Session executes delete statements only when the cache is cleaned.

The object is deleted from the session cache only when the close () method of session is called.

Session = HibernateUtil.currentSession (); s tx = session.beginTransaction (); Book oneBook= (Book) session.load (Book.class,bookID); session.delete (oneBook); tx.commit (); this article is about "what are the common methods of Sessin interfaces in Hibernate". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report