There are three kinds of basic strategies for inheritence mapping:
1. table per hierarchy.
2. table per subclass.
3. table per concreteclass.
Table structure maybe the root reason to determine which kind strategy will be used.
Table per hierarchy:
With subclass element.
A discriminator column will be used to distinguish subclass.
Limitation: no not null constraint on sub class's property.
Fault: redandance data will be generated.
Table per subclass:
With joined-class elment.
There are tables for super class and each subclass, for every subclass, key elemnt is used to referenced to super class's primary key, and all common properties will be stored in super table. The relation between super table and sub table is one-to-one.
Fault: complex table structure.
Table per concrete class:
With union-class elemnt.
Super class responsible for genrate id and all common properties wich will stored in sub table.
Fault: redandance data will be generated.
Limitation: all common column should used the same column name for the properties are defined in super class.
Walks an XML mapping document and produces the Hibernate configuration-time
metamodel (the classes in the mapping package)
1. parse "extend" attribute of subclass, unionclass, joinedclass which defined under <hibernate-mapping> element.
2. parse "meta" data element.
3. parse other subclass of root element.
1. Hibernate filter is used to give a definition condition in xml mapping files.
2. Ever session want to use it must enable the filter with name first.
3. filter is defined in xml with elment <filter-def> under <hibernate-mapping>, used <filter> element under <class> element.
4. give certain sql condition attribute either in <filter-def> or <filter>.
5. Support value to filter parameters in application.
The main purpose is to support global filter.
1. session.createSqlQuery(), in purpose to increase performance, execute sql directly. addScalar() method is used to sepcify type of columns, add entity to return certain entity instance.
2. session.getNamedQuery(), execute query defined in mapping files with <sql-query> element, the query can be a defined sql sentence or a procedure, property type and entity type can also be specifid by certain elment.
3. update, detelet, insert sql can be defined in xml mapping files also.
The finaly purpose of the query is to enchance performance.
1. Usage org.hibernage.Criteria interface is to compose criterians included in org.hibernate.criteria package.
2. Criteria interface inherit org.hibernate.criteria.CriterianSpecification, which only defined some mode value, e.g: flushmode, cach mode, maybe not a good implemnt.
3. Criterian was implemnt by org.hibernate.impl.criteriaImpl and created by org.hibernate.impl.SessionImplementor, translate class name and sesson to criterian.
4. Typical usage: session.createCriteria(class).add(Restriction.xx()).list;
5. Restriction is factory of org.hibernate.criteria.Criteriaon implementation.
Architecture : Define top level interface to compose low lever sub interface, easy to extense and maintain.
There are 2 kinds of factory : factory level and System level, factory responsible for every factory instance, System for all facotrys, (only 2 system factory property).
Evironment got properties for /hibernate.properties first, and then from System.getProperties() to ovrride old one!
Totally, Evironment represents properties.
1. Use interface type.
2. Ordered type collection has index sub-element.
3. Key element indicates the foreign key referred to entity own the collection.
4. "element" or "composite element" element is used to specify value type contained in collection.
5. "many-to-many" or "one-to-many" elmeent is used to sepcify referred type contained in collection.
6. one-to-many need not an intervening table.(foreign key)
Hard requirenment:
1. No-argument construct , package visiblity, usde instantiate object by Constructor.newInstance().
Option requirement:
1. Pojo.
2. Implement hashCode and equals for two resons :
1) Object will be store in a set property.
2) Instance span to sesssion scope, make a detached object persistent again, will call equals, for java indentify(==) and db indentify(pk) is not available for the condition(object doest not have identify before persistent),
Note: hashCode generation should not use indentify proeprty of object.
Hibernate configuration object is the core and starttime class , initiate it and call its config() method to initial sessionFactory.
Configuration get properties, mapping , etc information through two ways:
1. Config file: hibernate.propeties, system, hibernate.cfg.xml(optional, name changed Configuration.doConfig(*.cfg.xml)).
2. Method: Configuration.addSource, addProperties...
So config files is only a way of configuration to get config info.
Configuration: the class instantiate a sessionng factory, it works as follow:
1. Get properties for Enviroment.java. Environment get properties from hibernate.properties and System, System propertie is prior to hibernate.properties when name is equal.
2. Configuration.config will read hibernate.cfg.xml to get more properties and mapping files.
During last two steps, it will some util class in org.hibernate.util to help handle file.
3. Generate ConnectionProvider by its all properties.