Wednesday, November 12, 2014

Monday Notes

EXPLAIN ABOUT MAPPING FILE?
class:IN THIS WE WILL PROVIDE ENTITY COMPLETE NAME WITH PACKAGE NAME AND DATABASE TABLE NAME. IF WE WANT WE CAN PUT THE PACKAGE NAME IN ROOT ELEMENT.

ID: THIS TAG WILL REPRESENT THE PRIMARY KEY PROPERTY OF THE ENTITY TO TABLE COLUMN. IF WE CAN'T ABLE TO MAINTAIN PRIMARY KEYS THEN WE HAVE TO DEFINE COMPOSIT ID IN OUR MAPPING FILE. THESE ID OR COMPOSIT ID WILL TREAT AS A UNIQUE VALUES IN DATABASE SIDE.

MAPPING FILE CLASS RELATED INFORMATION IS CASE SENSITIVE. WHERE AS TABLE RELATED DATA IS NOT.

IF BOTH ENTITY AND TABLE PROPERTIES(COLUMN) NAMES ARE EQUAL THEN WE NO NEED TO PROVIDE COLUMN NAMES IN OUR MAPPING FILE.

WHEN WE DEFINE ENTITY BEAN, WHAT EVER THE PROPETIES WE DEFINED INIT ALL THE PROPERTIES ARE NOT REQUIRED TO BE MAPPED IN MAPPING FILE. IF WE DEFINE MORE PROPERTIES AND LESS COLUMNS EXIST IN TABLE THEN WHAT THE PROPERTIES MAPPED IN MAPPING THOSE PROPERTY VALUES WILL UPDATE ARE INSERT IN TABLE COLUMNS.

WE CAN ABLE TO CLUB ALL RELATED MODULES(ROOT AND SUB MODULES) IN SIGLE MAPPING FILE USING <FOR EACH CLASS/> TAG.

WHAT IS CONFIGURATION OBJECT?
OBJECT ORIENTED REPRESENTATION OF CONFIGURATION INFORMATION IS CREATED USING CONFIGURATION CLASS.

IF WE WANT TO CHANGE CONFIGURATION DEFAULT FILE NAME OR LOCATION THEN WE HAVE TO PROVIDE CONFIGRATION FILE LOCATION PATH INCLUDING NAME AS A PERAMETER WHEN WE ARE CREATING CONFIGURATION OBJECT.

THE CONFIGURATION INFORMATION WILL BE MAINTAINED AS VARIABLES IN OUR CONFIGURATION OBJECT. WHEN USING THIS CONFIGURATION OBJECT WE CAN ABLE TO CREATE SESSIONFACTORY(ROOT LEVEL OBJECT), THIS DATA WILL BE PROVIDED AS OBJECT FORMAT.

WE CAN ABLE TO SET CONFIGURATION INFORMATION AT THE TIME WHEN WE ARE CREATING CONFIGURATION OBJECT. EXAMPLE:

NOTE: WE CAN DEFINE CONFIGURATION INFORMATION PROGRAMETICALLY.(BUT IT IS AGAIN HARD CODED). SO THE CONFIGURATION OBJECT IS ONLY USED TO PROVIDE SESSIONFACOTY OBJECT.

WE ARE INITIATING HIBERNATE PERSISTENCE LAYER USING THIS CONFIGURATION OBJECT.

WHAT IS SESSIONFACTORY?
SESSIONFACTORY IS INTERFACE WHERE SESSIONFACTORYIMPL IS IMPLEMENTED CLASS.

IT IS PROVIDING SESSION OBJECTS.

SESSIONFACTORY IS HEAVY WEIGHT OBJECT SO WE HAVE TO MAKE IT SINGLETON AND IT IS PROVIDING LIGHT WEIGHT SESSION OBJECT.

SESSIONFACTORY IS THREAD SAFE.

SSIONFACTORY HAS TO BE CREATED OF INDIVIDUAL VENDROS(DATABASES). IF MULTIPLE VENDOR DATABASES ARE USED MULTIPLE CONFIGURATION FILES HAS TO BE CREATED.

SESSIONFACTORY IS RESPLONSIBLE FOR SECOND LEVEL CACHE.
















4 comments:

  1. Hello Sir,
    Here is the exception am getting, please check this out.

    Thanks.

    Exception in thread "main" org.hibernate.exception.JDBCConnectionException: Error calling Driver#connect
    at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator$1$1.convert(BasicConnectionCreator.java:122)
    at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.convertSqlException(BasicConnectionCreator.java:140)
    at org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.java:58)
    at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.createConnection(BasicConnectionCreator.java:75)
    at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:106)
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:89)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:206)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:178)
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:260)
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:94)
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:89)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:206)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:178)
    at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1885)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1843)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1928)
    at str.ClientForSave.main(ClientForSave.java:14)
    Caused by: java.sql.SQLException: Io exception: The Network Adapter could not establish the connection
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:255)
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:387)
    at oracle.jdbc.driver.PhysicalConnection.(PhysicalConnection.java:414)
    at oracle.jdbc.driver.T4CConnection.(T4CConnection.java:165)
    at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)
    at org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.java:55)
    ... 14 more

    ReplyDelete
  2. Getting this exception in both Oracle as well as MySql

    ReplyDelete
  3. Hi Prabhakar...

    Ya you are right. There was problem with proper configuration only. But its resolved.

    Thanks for reply.

    ReplyDelete
  4. Good to see the communication between the students.....

    ReplyDelete