Mock tests, Interview questions, Tutorials and Tech news
 
 

Archive

Posts Tagged ‘hibernate’

Hibernate Search – Getting Started

June 15th, 2010 smitha 20 comments

Once your dynamic site has gone bigger, data in relational database has grown, there is always a need for searching the contents. SQL queries with like ‘%…%’ are useful. But to do multiple columns / table searching, we’ll need to have big SQL queries with different conditions, ANDed and ORed. Such searching is not realistic and can not be maintained and extended easily.
For Hibernate users, Hibernate search helps searching rows from database. Without writing any complex SQL queries, you can search multiple columns and get related objects from db.

In our site Skill-Guru , you will notice a search box on the right hand side.  We have enabled the search on few tables and columns initially. Currently it will search for the tests , description and keywords for the input keyword.

Read more…

One-to-One mapping in Hibernate using Foreign Key Association

February 16th, 2010 smitha 8 comments

One-to-One mapping can be done in 2 ways:

  1. Primary key association:
  2. Foreign key association.

My previous post described about the Primary key one-to-one mapping in Hibernate. This post gives an example of Foreign key one-to-one association in Hibernate. Read more…

Mapping Composite Keys in Hibernate

February 10th, 2010 smitha 7 comments

In Real world applications it is natural to have tables with composite keys. The row will be identified with combination of key  column values of a row.

Consider Following scenario:

A test selling website defines tests and customers.

Read more…

One-to-One mapping in Hibernate

February 8th, 2010 smitha 7 comments

In Hibernate One-to-One mapping can be done in 2 ways: 

  1. Primary key association:
  2. Foreign key association. 

This article describes how a Primary key One-to-one association can be done. 

Consider a Customer and address entities. Each customer will have one address. And an address is associated with one customer.  To make this relationship work in database customer and address will have same Id(primary key). Mapping this kind of relationship in Hibernate is called primary key One-to-One association. Doing so will help you saving, updating, deleting related entities easy.

Read more…

Transaction Management in Hibernate- Part I

December 17th, 2009 smitha No comments

Transaction: Transaction simply means a unit of work, which is atomic. If only one step fails, then the whole unit of work fails.  When we consider database, Transaction groups a set of statements/commands which gets committed together. If a single statement fails, whole work will be rolled back.   Transactions can be described using ACID criteria. Read more…

saveOrUpdate Method in Hibernate

October 22nd, 2009 Vinay 2 comments

There is some bit of confusion with hibernate users as to what exactly saveorUpdate method does . saveOrUpdate is general purpose method that either saves a transient instance by generating a new identifier or updates/reattaches the detached instances associated with its current identifier.

I have seen people using saveOrUpdate() instead of an update. Hibernate doc clearly says that update() or saveOrUpdate() is to be used in the following scenario: Read more…

Some useful options in Class element in Hibernate

October 22nd, 2009 smitha No comments

Hibernate mapping: the <Class> element: Some useful options

In hibernate mapping file the <class> element maps the domain object with corresponding entity in the database. It will be defined under <hibernate-mapping> tag. <Hibernate-mapping> tag also allows multiple <class> tags inside it. (i.e we can save multiple class mapping information in a single file).

A sample class element looks like below:

<hibernate-mapping>

<class table=”user_tasks” >

<id column=”user_task_id”>

<generator>

</generator>

</id>

.

.

.

</class>

</hibernate-mapping>

Here we don’t discuss all the class element attributes, but some which I found very useful: Read more…

Hibernate – Represent Entity Data in XML

October 14th, 2009 smitha No comments

One of the feature I liked about hibernate is its ability to represent the db data in XML. Without much work, the entity data will be converted into XML. One can fetch table data similar to normal loading and can get its representation in XML.

Read more…

Get Adobe Flash playerPlugin by wpburn.com wordpress themes