google Analytics

Monday, August 30, 2010

named query in hibernate

Hibernate Named Queries Example
Using Named Query
named query example

Calling a named query
In Hibernate, the getNamedQuery() method obtains a Query instance for a named query:
session.getNamedQuery("findItemsByName")
.setString("desc", description);



Java
Persistence also supports named
queries
:
em.createNamedQuery("
findItemsByName").setParameter("desc",
description);

 


Named queries don't have to be HQL or JPA QL strings; they may even be native
SQL queries—and your Java code doesn't
need to know the difference:

<sql-query name="findItemsByName">
<return alias="item"
class="Item"/>
<![CDATA[
select {item.*}
from item where name like :desc
]]>
</sql-query>



named query with annotations

Assume you consider
a particular named query to belong to a particular entity class:

package auction.model

import ...;

@NamedQueries({

@NamedQuery(
name = "findItemsByName",
query = "select i from Item i where i.name like :name"
),
...
})
@Entity
@Table(name = "ITEM")
public class Item { ... }


Named Query Hibernate
hibernate named
query annotation
http://opensourceframework.blogspot.com/2010/07/hibernate-named-query-example.html



named query in hibernate


hibernate named query example


Anish

No comments:

Post a Comment