You are on page 1of 2

Assignment 8

1. Write examples of following files.


a) Hibernate configuration xml file
b) Hibernate Mapping Xml
Ans:
a) XML file
<hibernate-mapping>
<class name="POJO class name" table="table name in database">
<id name="variable name" column="column name in database"
type="java/hibernate type" />
<property name="variable1 name" column="column name in database"
type="java/hibernate type" />
<property name="variable2 name" column="column name in database"
type="java/hibernate type" />
</class>
</hibernate-mapping>

b) Mapping XML

<hibernate-mapping>

<class name="POJO class name" table="table name in database">


<id name="variable name" column="column name in database"
type="java/hibernate type" />
<property name="variable1 name" column="column name in database"
type="java/hibernate type" />
<property name="variable2 name" column="column name in database"
type="java/hibernate type" />
</class>

</hibernate-mapping>
2. Explain following clause in HQL (Hibernate Query Language.)
a. Select
b. where
c. update
Ans:
a) An HQL SELECT is used to query the database for classes and their
properties. Here’s the syntax of the SELECT statement:
[SELECT [DISTINCT] property [, ...]]
FROM path [[AS] alias] [, ...] [FETCH ALL PROPERTIES]
WHERE logicalExpression
GROUP BY property [, ...]
HAVING logicalExpression
ORDER BY property [ASC | DESC] [, ...]

b) Where Clause is used to limit the results returned from database. It can be
used with aliases and if the aliases are not present in the Query, the
properties can be referred by name. For example:
from UserDetails user where user.userId = 3

c) UPDATE alters the details of existing objects in the database. In-memory


entities, managed or not, will not be updated to reflect changes resulting
from issuing UPDATE statements. Here’s the syntax of the UPDATE
statement:
UPDATE [VERSIONED]
[FROM] path [[AS] alias] [, ...]
SET property = value [, ...]
[WHERE logicalExpression]

You might also like