3 types of mapping for inheritance
Hibernate collection
1. Set
2. List - use index property to set index no, table must have index column
3. Map - use index property to set key, table must have key column defined.
One-to-One
If a class has two same type of property e.g. HomeAddress & CompanyAddress.
customer mapping uses: many-to-one
Address uses: one-to-one, we can setup property-ref="homeAddress", so that we can setup binary-relationship between homeAddress and Customer. but NOT companyAddress and Customer again.
Can use one-to-one on both side. they will share one primary key
Hibernate Configure
max_fetch_depth : defines length of relationship from the entity you want to retrieve.
e.g. In this relationship School--->Student--->Subject
if you want to read School and set max_fetch_depth '1', then you can only retrieve School + Students.
fetch strategy
1. Select - lazy loading
2. Join - immediate load related entities.
3. subselect - use subQuery
batch-size (select one entity which has reference to a collection)
Help hibernate to reduce n times of query into one to save time.
Hibernate optimize the second SELECT (either lazy or non-lazy) by fetching up to N other collections
To tell Hibernate to use the latter solution is to tell it that a certain class is batch-able . You do this by adding the batch-size
attribute to either a.) the entity definition for the association being fetched (e.g. the definition for the Owner
class) or b.) the collection definition on a class with a collection mapping
* 是设定对数据库进行批量删除,批量更新和批量插入的时候的批次大小,有点相当于设置Buffer缓冲区大小的意思。
@BatchSize=16
defines one-to-many relationship
fetch-size
Gives the JDBC driver a hint as to the number of rows that should be fetched from the database when more rows are needed. The number of rows specified affects only result sets created using this statement. If the value specified is zero, then the hint is ignored. The default value is zero.
*设定JDBC 的Statement读取数据的时候每次从数据库中取出的记录条数。
* A non-zero value determines the JDBC fetch size (calls Statement.setFetchSize()
).
Reference:
http://www.mkyong.com/hibernate/hibernate-fetching-strategies-examples/
http://docs.jboss.org/hibernate/core/3.3/reference/en/html/session-configuration.html
http://community.jboss.org/wiki/AShortPrimerOnFetchingStrategies
http://www.javalobby.org/java/forums/m91885142.html
http://hi.baidu.com/lifa868/blog/item/1326b6da3f60696cd1164ef2.html/cmtid/3e42a1dc3a02b4d78c1029a8