|
| 1 | +## Instructions |
| 2 | +- For best viewing experience on your phone switch to Desktop Mode |
| 3 | +- To view the entire page on phone click on **View all of README.md** |
| 4 | +- Best viewed on PC |
| 5 | + |
| 6 | +## Navigation |
| 7 | +- [Hibernate FAQs](#hibernate-faqs) |
| 8 | +- [Spring FAQs](#spring-faqs) |
| 9 | + |
| 10 | + |
| 11 | +* * * |
| 12 | + |
1 | 13 | ## Hibernate FAQs
|
2 | 14 |
|
3 | 15 | 1. __`hibernate.cfg.xml` file__<br>
|
|
13 | 25 | - create-drop
|
14 | 26 | - validate
|
15 | 27 |
|
16 | | -2. __Persistent Object & Collection Object__<br> |
| 28 | +2. __Persistent Object__<br> |
17 | 29 | Persistent Object : <br>
|
18 | 30 | > Persistent objects are instances of POJO classes that you create that represent rows in the table in the database.
|
19 | 31 | > According to hibernate-doc an instance of POJO class representing table in database goes through 3 states of which persistent is one of them.
|
20 | 32 |
|
21 | | - Collection Object : <br> |
22 | | - |
23 | 33 | 3. __Bag Collection__<br>
|
24 | 34 | A Bag is a java collection that stores elements without caring about the sequencing, but allow duplicate elements in the list. A bag is a random grouping of the objects in the list. A Collection is mapped with a `<bag>` element in the mapping table and initialized with `java.util.ArrayList`.
|
25 | 35 |
|
26 | | -4. __Collection Mapping in Hibernate using XML__<br> |
27 | | -5. __In which state object is not associated with Session__<br> |
| 36 | +4. __In which state object is not associated with Session__<br> |
28 | 37 | Transient & Detached
|
29 | 38 |
|
30 | | -6. __Different `@Annotations` in Hibernate__<br> |
| 39 | +5. __Different `@Annotations` in Hibernate__<br> |
31 | 40 | - `@Entity`
|
32 | 41 | - `@Column`
|
33 | 42 | - `@Id`
|
34 | 43 | - `@GeneratedValue`
|
35 | 44 |
|
36 | | -7. __Different types of Association Mapping in Hibernate__<br> |
| 45 | +6. __Different types of Association Mapping in Hibernate__<br> |
37 | 46 | - OneToOne
|
38 | 47 | - OneToMany
|
39 | 48 | - ManyToOne
|
40 | 49 | - ManyToMany
|
41 | 50 |
|
42 | | -8. __`get()` v/s `load()`__<br> |
| 51 | +7. __`get()` v/s `load()`__<br> |
43 | 52 | <table>
|
44 | 53 | <tr>
|
45 | 54 | <th><samp>get()</samp></th>
|
|
63 | 72 | </tr>
|
64 | 73 | </table>
|
65 | 74 |
|
66 | | -9. __Different Hibernate Inheritence Strategies__<br> |
| 75 | +8. __Different Hibernate Inheritence Strategies__<br> |
67 | 76 | - Table Per Hierarchy
|
68 | 77 | - `@Inheritance(strategy=InheritanceType.SINGLE_TABLE) `
|
69 | 78 | - Table Per Concrete class
|
70 | 79 | - `@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)`
|
71 | 80 | - Table Per Subclass
|
72 | 81 | - `@Inheritance(strategy=InheritanceType.JOINED)`
|
73 | 82 |
|
74 | | -10. __First Level Cache & Second Level Cache__<br> |
| 83 | +9. __First Level Cache & Second Level Cache__<br> |
75 | 84 | First Level Cache:
|
76 | 85 | > First level is maintained at the Session level and accessible only to the Session.
|
77 | 86 | > Can use the first level cache to store local data i.e. the data which is needed by the Session
|
|
80 | 89 | > Second level cache is maintained at the SessionFactory level and available to all Sessions.
|
81 | 90 | > Can use the second level cache to store global data i.e. something which can be shared across sessions.
|
82 | 91 |
|
83 | | -11. __Hibernate Architecture Layers__<br> |
| 92 | +10. __Hibernate Architecture Layers__<br> |
84 | 93 | 3 Main Layers
|
85 | 94 | - Java Application Layer
|
86 | 95 | - Hibernate Framework Layer
|
87 | 96 | - Backend API Layer _(Optional)_
|
88 | 97 | - DB Layer
|
89 | 98 |
|
90 | | -12. __What is Hibernate?__<br> |
| 99 | +11. __What is Hibernate?__<br> |
91 | 100 | 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.
|
92 | 101 |
|
93 | | -13. __Configuration in Hibernate__<br> |
| 102 | +12. __Configuration in Hibernate__<br> |
94 | 103 | - Combination of Configuration XML and Mapping XML file
|
95 | 104 | - Annotations
|
96 | 105 |
|
97 | | -14. __Advantages and Jobs of ORM__<br> |
| 106 | +13. __Advantages and Jobs of ORM__<br> |
98 | 107 | 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.
|
99 | 108 |
|
100 | 109 | _Advantages:_
|
101 | 110 | - Speeds-up Development - eliminates the need for repetitive SQL code.
|
102 | 111 | - Overcomes vendor specific SQL differences - the ORM knows how to write vendor specific SQL so you don't have to.
|
103 | 112 |
|
104 | | -15. __Criteria Query & How to create it__<br> |
| 113 | +14. __Criteria Query & How to create it__<br> |
105 | 114 | 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.
|
106 | 115 |
|
107 | 116 | 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.
|
108 | 117 |
|
109 | | -16. __Significance of `hbm2ddl.auto`__<br> |
| 118 | +15. __Significance of `hbm2ddl.auto`__<br> |
110 | 119 | `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.
|
111 | 120 | - *validate*: validate the schema, makes no changes to the database.
|
112 | 121 | - *update*: update the schema.
|
113 | 122 | - *create*: creates the schema, destroying previous data.
|
114 | 123 | - *create-drop*: drop the schema when the SessionFactory is closed explicitly, typically when the application is stopped.
|
115 | 124 |
|
116 | | -17. __Significance of Session object in Hibernate__<br> |
| 125 | +16. __Significance of Session object in Hibernate__<br> |
117 | 126 | 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.
|
118 | 127 |
|
119 | | -18. __Methods of Session object__<br> |
| 128 | +17. __Methods of Session object__<br> |
120 | 129 | - `beginTransaction()`
|
121 | 130 | - `save()`
|
122 | 131 | - `update()`
|
|
128 | 137 | - `flush()`
|
129 | 138 | - `delete()`
|
130 | 139 |
|
131 | | -19. __EAGER v/s LAZY loading__<br> |
| 140 | +18. __EAGER v/s LAZY loading__<br> |
132 | 141 | Lazy loading:
|
133 | 142 | > 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.
|
134 | 143 | > It simply delays the loading of the related data, until you ask for it.
|
|
137 | 146 | > 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.
|
138 | 147 | > 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.
|
139 | 148 |
|
140 | | -20. __Significance of HQL__<br> |
| 149 | +19. __Significance of HQL__<br> |
141 | 150 | 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:
|
142 | 151 | - Provides full support for relational operations.
|
143 | 152 | - Return results as objects.
|
|
146 | 155 | - Supports many advanced features as compared to SQL, such as pagination, fetch join etc.
|
147 | 156 | - Provides database independency.
|
148 | 157 |
|
149 | | -21. __Important components in Hibernate Architecture__<br> |
| 158 | +20. __Important components in Hibernate Architecture__<br> |
150 | 159 | - Configuration Object
|
151 | 160 | - SessionFactory Object
|
152 | 161 | - Session Object
|
153 | 162 | - Transaction Object
|
154 | 163 | - Query Object
|
155 | 164 | - Criteria Object
|
156 | 165 |
|
157 | | -22. __LifeCycle states of an object in Hibernate__<br> |
| 166 | +21. __LifeCycle states of an object in Hibernate__<br> |
158 | 167 | - Transient State
|
159 | 168 | > 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.
|
160 | 169 | - Persistent State
|
|
164 | 173 | - Removed State
|
165 | 174 | > 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.
|
166 | 175 |
|
167 | | -23. __Different annotations used in `@ManyToMany` Association__<br> |
| 176 | +22. __Different annotations used in `@ManyToMany` Association__<br> |
168 | 177 | - `@JoinTable`
|
169 | 178 | - `@JoinColumn`
|
170 | 179 |
|
171 | | -24. __Properties in `HBM XML` file__<br> |
| 180 | +23. __Properties in `HBM XML` file__<br> |
172 | 181 | - The mapping document is an XML document having `<hibernate-mapping>` as the root element, which contains all the `<class>` elements.
|
173 | 182 |
|
174 | 183 | - The `<class>` elements are used to define specific mappings from a Java classes to the database tables. The Java class name is specified using the name attribute of the class element and the database table name is specified using the table attribute.
|
|
181 | 190 |
|
182 | 191 | - The `<property>` element is used to map a Java class property to a column in the database table. The name attribute of the element refers to the property in the class and the column attribute refers to the column in the database table. The type attribute holds the hibernate mapping type, this mapping types will convert from Java to SQL data type.
|
183 | 192 |
|
184 | | -25. __Named Query & Criteria Query__<br> |
| 193 | +24. __Named Query & Criteria Query__<br> |
185 | 194 | - Named Query:
|
186 | 195 | > A named query is a statically defined query with a predefined unchangeable query string. They're validated when the session factory is created, thus making the application to fail fast in case of an error.
|
187 | 196 | - Criteria Query:
|
|
0 commit comments