Sponsored Links
Ad by Google
Hibernate is an Open source Object Relational Mapping framework. It enables developer to develop classes to be persist in an object oriented way including inheritance and the Java collections framework. Current hibernate stable release is 4.3.5 that was released in April 2014. It has various classes and interfaces, but sometimes interviewer ask you to list down the core classes and interfaces of hibernate.
Well hibernate has various classes and interfaces, but when we say core classes and interfaces those are listed below, they all are the exceptional role in hibernate library.- Configuration (class)
- ServiceRegistry (interface)
- SessionFactory (interface)
- Session (interface)
- Transaction (interface)
- Query (interface)
Syntax:
Configuration configuration = new Configuration();
configuration.configure();
ServiceRegistry: Is an interface resides inside the org.hibernate.service package. ServiceRegistry is all about access management of services. To build ServiceRegistry instance you need ServiceRegistryBuilder class.
Syntax:
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
Update, From Hibernate 4.3 ServiceRegistryBuilder is deprecated. If you are using hibernate 4.3 then use the below one instead of the above.
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
SessionFactory: Is an interface available inside the org.hibernate package. It's all about the factory of session, you can create and open a session from the SessionFactory. Basically an application has a single sessionFactory instance which is a thread safe.
Syntax:
SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
Session: Is an interface available inside the org.hibernate package. The heart of the hibernate is a session. It's a runtime interface between your application and hibernate. Session is a single threaded short lived object, Session instances obtain from the SessionFactory.
Syntax:
Session session = sessionFactory.openSession();
Transaction: Is an interface available inside the org.hibernate package. Transaction as it's name implies it allows the application to define there units of work into a single transaction. A transaction is associated with Session.
Syntax:
session.beginTransaction();
session.save(user);
session.update(user_payrole);
session.getTransaction().commit();
Query: Is an interface available inside the org.hibernate package. Query is all about the object oriented representation of hibernate query. A Query instance is obtained by calling session.createQuery().
Syntax:
session.createQuery("from User").list();
References:
Reference1
Reference2
Sponsored Links
0 comments:
Post a Comment