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 can be done in 2 ways:
- Primary key association:
- 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…
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…
In Hibernate One-to-One mapping can be done in 2 ways:
- Primary key association:
- 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: 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…
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…
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…
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…