2. Agenda
1) Mapping : Many to One
2) Mapping : One to Many
3) Mapping : One to One
4) Batch Processing
5) Data Filtering
6) Interceptors and Events
7) Triggers and Stored Procedure
7) Hibernate Reverse Engineering
8) 2nd
Level Cache
3. Hibernate Many To One
● A many-to-one association is the most common kind
of association where an Object can be associated
with multiple objects
● Author and book relations.
● Lets look at the code here.
4. Hibernate One to Many
● A One-to-Many mapping can be implemented using
a Set java collection that does not contain any
duplicate element.
● Employee and Certificate.
● Lets look at the code.
5. Hibernate One to One
● You got the idea by reaching here ?
● A one-to-one association is similar to many-to-one
association with a difference that the column will be
set as unique
6. Hibernate Batch Insert
● It should be batch update using SQL.
● You can write SQL queries and run it in Hibernate.
● It will NOT update the Persistent objects AFTER
SQL UPDATE.
● You have to flush the session
7. Hibernate Batch Insert
● It should be batch update using SQL.
● You can write SQL queries and run it in Hibernate.
● It will NOT update the Persistent objects AFTER
SQL UPDATE.
● You have to flush the session
8. Data Filtering
● Limit the amount of data visible without modifying
query parameters
● Used for security purposes.
9. Interceptors and Events
● Callbacks from the session allowing the application
to inspect and/or manipulate properties of a
persistent object
● Two types :
● Session scope.
● Session Factory Scope.
10. Triggers
● Identify columns that are modified automatically by
the database in the object mapping file.
● Also need to tell Hibernate NOT to insert or update
these columns, as appropriate
12. 2nd
Level Cache
● First level is the session cache. Lives for session
● Second Level Cache is across the sessions.
● Second level cache will be used when the objects are
loaded using their primary key.
● Query Cache : When the query cache is turned on,
the results of the query are stored against the
combination query and parameters. Every time the
query is fired the cache manager checks for the
combination of parameters and query.
13. Hibernate Reverse Engineering
● Me : I am lazy toad. Its Sunday and I dont want to
do the hibernate mapping. Please help.
● Hibernate : Hey I can get you mappings from the
DB tables.
● Me: Oo la la.
14. Reference
Reference example from :
http://www.tutorialspoint.com/hibernate/hibernate_ma
http://courses.coreservlets.com/Course-Materials/hibernate.html
ACM Hibernate ORMCode