Hibernate query solution

xiaoxiao2021-04-07  345

These two weeks have been achieved by using the test tool developed by Struts to implement Struts Hibernate. First, from the mood, always keep a happy peace during the development process, "It turned out to be so happy?" It is high efficiency in development efficiency.

Now Sun joins JDOCENTRAL.COM and starts to start JDO2.0. Think about it will be an exciting experience after it is waiting for it. Let us wait and see.

It is very simple to use Hibernate to manipulate lasting data. Some simple queries here will have brought it. This article focuses on some of my experience when integrated inquiry and paging. If netizens think that my program is still inadequate, please I discuss, my email: Plateau_t@sina.com.

The first part: Hibernate provides the query interface or method thereof (this section does not do it, please refer to the Hibernate manual)

1. According to ID query

To use the LOAD method of the Session interface.

Load (Class Theclass, Serializable ID)

Load (Class Theclass, Serializable ID, LockMode Lockmode)

LOAD (Object Object, Serializable ID)

2. HQL statement for query

2.1 Using the Query interface, Query is generated by CREATEQUERY () in the session.

1) Query without parameters (such relatively simple)

Query Query = session.createQuery ("SELECT User from User As User);

2) Query with parameters

Query Query = session.createQuery ("SELECT User from User AS User Where User.Name =?");

Query.setString (0, name) // Assume Name to pass the parameters

Query Query = session.createQuery ("Select User from User AS User Where.Name =: Name");

Query.setString ("name", name) // assumes that Name is a parameter passed

(Multiple parameters are pushed in this class)

Using the SESSION interface for the Find query

Find (String Query)

Find (String Query, Object [] VALUES, TYPE [] TYPES

Find (String Query, Object Value, Type Type) Returns List

Such as:

List list = session.find ("SELECT User from users as user where user.name =?", Name, hibernate.string

List list = session.find ("SELECT User from users as user where user.name =? And user.pw =?", New object [] {name, pw}, new type [] {hibernate.string, hibernate.string })

{Recommended Query method to query}

转载请注明原文地址:https://www.9cbs.com/read-132527.html

New Post(0)