Hibernate - Interview Questions and Answers on Hibernate Annotations

Q1.  Name few Hibernate annotations ?

Ans. 

@Entity
@Table
@Id 
@Column
@Temporal
@Basic
@Enumerated
@Access
@Embeddable
@Lob
@AttributeOverride
@Embedded
@GeneratedValue
@ElementCollection
@JoinTable
@JoinColumn
@CollectionId
@GenericGenerator
@OneToOne
@OneToMany
@ManyToOne
@ManyToMany
@NotFound


Q2.  What is the difference between these 2 annotations ?

@Entity

@Entity ( name="EMPLOYEES" )


Ans. The first annotation will try to map the Class with the Table as of same name as Class whereas the second annotation will specify the Entity name as "EMPLOYEES" and hence will try to map with Table Name "EMPLOYEES".

Q3.  "What is the difference between these 2 annotations ?

@Entity ( name ="EMPLOYEES")

@Entity
@Table ( name=""EMPLOYEES"" )

@Entity ( name="EMP")
@Table ( name="EMPLPYEES" )

Ans. First Annotation will set the Entity name as EMPLOYEES and hence will try to map with the same Table name.

The second annotation will make the Entity mapped to table EMPLOYEES irrespective of the Entity Name ( which is class name in this case ).

Third Annotations will set the different names for Enitity and Table and will explicitly map them.

Q4.  How to do Eager loading in Hibernate ?

Ans. Using

lazy = false in hibernate config file

or

@Basic(fetch=FetchType.EAGER) at the mapping



Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner
comments powered by Disqus