could any one please tell me what is the naming convention the Hibernate developers fallowing to give names for DAO calass, Sesgleton class which create Single SessionFactory and retuns Session throug a static method, hibernate mapping files etc
I can only answer from my rather limited experience and perspective, but I'm happy with and used to the way we do it. In general, we use an abstract class called DatabaseHelper
that has a lot of static methods. Examples:
DatabaseHelper.getSession()
returns a Session
. The two methods
DatabaseHelper.commitTransaction()
and
DatabaseHelper.beginTransaction()
handle the transactions.
Beans have no naming convention, but all extend
public abstract class HibernateBean<T> implements Serializable
Like this
@Entity
@Table(name = "table_name")
public class TableEntry extends HibernateBean<TableEntry> {
The HibernateBean
contains some methods like getId()
to retrieve the Hibernate-generated id.
This is highly subjective but here is what I use:
names for DAO class
For an Order
entity, I use OrderDao
for the interface and HibernateOrderDao
for the Hibernate implementation (a JPA based implementation would be JpaOrderDao
, etc).
class which create Single SessionFactory and retuns Session throug a static method
I use the traditional HibernateUtil
(and you'll find many references in the Hibernate documentation, literature, etc). Here is an example. There is a more sophisticated version in the Caveat Emptor sample app.
- hibernate mapping files
A class named foo.bar.Foo
would be mapped by a foo/bar/Foo.hbm.xml
file. First, this makes mappings easy to organize, to find and ease the maintenance. Second, this allows to use the strongly typed Configuration#addClass(Class)
method (which is refactoring resistant).