|
40 | 40 | - ManyToMany
|
41 | 41 |
|
42 | 42 | 8. __`get()` v/s `load()`__<br>
|
43 | | - `get()`|`load()` |
44 | | - ----------|---------- |
45 | | - Returns null if an object is not found. | Throws ObjectNotFoundException if an object is not found. |
46 | | - get() method always hit the database. | load() method doesn't hit the database. |
47 | | - get() returns the real object, not the proxy. | load() returns proxy object. |
48 | | - get() should be used if you are not sure about the existence of instance. | load() should be used if you are sure that instance exists. |
| 43 | + <table> |
| 44 | + <tr> |
| 45 | + <th><samp>get()</samp></th> |
| 46 | + <td><samp>load()</samp></th> |
| 47 | + </tr> |
| 48 | + <tr> |
| 49 | + <td>Returns null if an object is not found.</td> |
| 50 | + <td>Throws ObjectNotFoundException if an object is not found.</td> |
| 51 | + </tr> |
| 52 | + <tr> |
| 53 | + <td><samp>get()</samp> method always hit the database.</td> |
| 54 | + <td><samp>load()</samp> method doesn't hit the database.</td> |
| 55 | + </tr> |
| 56 | + <tr> |
| 57 | + <td><samp>get()</samp> returns the real object, not the proxy.</td> |
| 58 | + <td><samp>load()</samp> returns proxy object.</td> |
| 59 | + </tr> |
| 60 | + <tr> |
| 61 | + <td><samp>get()</samp> should be used if you are not sure about the existence of instance.</td> |
| 62 | + <td><samp>load()</samp> should be used if you are sure that instance exists.</td> |
| 63 | + </tr> |
| 64 | + </table> |
| 65 | + |
| 66 | + | |
| 67 | + | |
| 68 | + | |
49 | 69 |
|
50 | 70 | 9. __Different Hibernate Inheritence Strategies__<br>
|
51 | 71 | - Table Per Hierarchy
|
|
74 | 94 | 12. __What is Hibernate?__<br>
|
75 | 95 | Hibernate is a Java framework that simplifies the development of Java application to interact with the database. It is an open source, lightweight, ORM (Object Relational Mapping) tool. Hibernate implements the specifications of JPA (Java Persistence API) for data persistence.
|
76 | 96 |
|
77 | | -14. __Configuration in Hibernate__<br> |
| 97 | +13. __Configuration in Hibernate__<br> |
78 | 98 | - Combination of Configuration XML and Mapping XML file
|
79 | 99 | - Annotations
|
80 | 100 |
|
81 | | -15. __Advantages and Jobs of ORM__<br> |
| 101 | +14. __Advantages and Jobs of ORM__<br> |
82 | 102 | ORM stands for Object/Relational mapping. It is the programmed and translucent perseverance of objects in a Java application in to the tables of a relational database using the metadata that describes the mapping between the objects and the database. It works by transforming the data from one representation to another.
|
83 | 103 |
|
84 | 104 | _Advantages:_
|
85 | 105 | - Speeds-up Development - eliminates the need for repetitive SQL code.
|
86 | 106 | - Overcomes vendor specific SQL differences - the ORM knows how to write vendor specific SQL so you don't have to.
|
87 | 107 |
|
88 | | -16. __Criteria Query & How to create it__<br> |
| 108 | +15. __Criteria Query & How to create it__<br> |
89 | 109 | Hibernate provides alternate ways of manipulating objects and in turn data available in RDBMS tables. One of the methods is Criteria API, which allows you to build up a criteria query object programmatically where you can apply filtration rules and logical conditions.
|
90 | 110 |
|
91 | 111 | The Hibernate `Session` interface provides `createCriteria()` method, which can be used to create a `Criteria` object that returns instances of the persistence object's class when your application executes a criteria query.
|
92 | 112 |
|
93 | | -17. __Significance of `hbm2ddl.auto`__<br> |
| 113 | +16. __Significance of `hbm2ddl.auto`__<br> |
94 | 114 | `hibernate.hbm2ddl.auto` Automatically validates or exports schema DDL to the database when the SessionFactory is created. With create-drop, the database schema will be dropped when the SessionFactory is closed explicitly.
|
95 | 115 | - *validate*: validate the schema, makes no changes to the database.
|
96 | 116 | - *update*: update the schema.
|
97 | 117 | - *create*: creates the schema, destroying previous data.
|
98 | 118 | - *create-drop*: drop the schema when the SessionFactory is closed explicitly, typically when the application is stopped.
|
99 | 119 |
|
100 | | -18. __Significance of Session object in Hibernate__<br> |
| 120 | +17. __Significance of Session object in Hibernate__<br> |
101 | 121 | A Session is used to get a physical connection with a database. The Session object is lightweight and designed to be instantiated each time an interaction is needed with the database. Persistent objects are saved and retrieved through a Session object.
|
102 | 122 |
|
103 | | -19. __Methods of Session object__<br> |
| 123 | +18. __Methods of Session object__<br> |
104 | 124 | - `beginTransaction()`
|
105 | 125 | - `save()`
|
106 | 126 | - `update()`
|
|
112 | 132 | - `flush()`
|
113 | 133 | - `delete()`
|
114 | 134 |
|
115 | | -20. __EAGER v/s LAZY loading__<br> |
| 135 | +19. __EAGER v/s LAZY loading__<br> |
116 | 136 | Lazy loading:
|
117 | 137 | > Lazy Loading. It is the default behavior of an Entity Framework, where a child entity is loaded only when it is accessed for the first time.
|
118 | 138 | > It simply delays the loading of the related data, until you ask for it.
|
|
121 | 141 | > Eager Loading helps you to load all your needed entities at once; i.e., all your child entities will be loaded at single database call.
|
122 | 142 | > This can be achieved, using the Include method, which returs the related entities as a part of the query and a large amount of data is loaded at once.
|
123 | 143 |
|
124 | | -21. __Significance of HQL__<br> |
| 144 | +20. __Significance of HQL__<br> |
125 | 145 | It is more beneficial to use HQL instead of native SQ retrieve data from databases. The following are some of the reasons why HQL is preferred over SQL:
|
126 | 146 | - Provides full support for relational operations.
|
127 | 147 | - Return results as objects.
|
|
130 | 150 | - Supports many advanced features as compared to SQL, such as pagination, fetch join etc.
|
131 | 151 | - Provides database independency.
|
132 | 152 |
|
133 | | -22. __Important components in Hibernate Architecture__<br> |
| 153 | +21. __Important components in Hibernate Architecture__<br> |
134 | 154 | - Configuration Object
|
135 | 155 | - SessionFactory Object
|
136 | 156 | - Session Object
|
137 | 157 | - Transaction Object
|
138 | 158 | - Query Object
|
139 | 159 | - Criteria Object
|
140 | 160 |
|
141 | | -23. __LifeCycle states of an object in Hibernate__<br> |
| 161 | +22. __LifeCycle states of an object in Hibernate__<br> |
142 | 162 | - Transient State
|
143 | 163 | > A transient state is one where hibernate session is not associated with the object instance and does not represent a row in the database table.
|
144 | 164 | - Persistent State
|
|
148 | 168 | - Removed State
|
149 | 169 | > When the persistent object is deleted from the database, it is passed to the session’s `delete(obj)` method. At this state, java instance exists but any changes made to the object are not saved to the database.
|
150 | 170 |
|
151 | | -24. __Different annotations used in `@ManyToMany` Association__<br> |
| 171 | +23. __Different annotations used in `@ManyToMany` Association__<br> |
152 | 172 | - `@JoinTable`
|
153 | 173 | - `@JoinColumn`
|
154 | 174 |
|
|
0 commit comments