Hibernate - Interview Questions and Answers for 'Annotations' | Search Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com

Search Interview Questions


 More than 3000 questions in repository.
 There are more than 900 unanswered questions.
Click here and help us by providing the answer.
 Have a video suggestion.
Click Correct / Improve and please let us know.
Label / Company      Label / Company / Text

   



Hibernate - Interview Questions and Answers for 'Annotations' - 28 question(s) found - Order By Newest

 Q1. What are concepts introduced with Java 5 ?Core Java
Ans. Generics , Enums , Autoboxing , Annotations and Static Import.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   java5   generics   enum   autoboxing   annotations   static import        rare

Try 1 Question(s) Test


 Q2. Which annotations are used in Hibernate ?Hibernate
Ans. @Entity
@Table
@Id
@Column
@Temporal
@Basic
@Enumerated
@Access
@Embeddable
@Lob
@AttributeOverride
@Embedded
@GeneratedValue
@ElementCollection
@JoinTable
@JoinColumn
@CollectionId
@GenericGenerator
@OneToOne
@OneToMany
@ManyToOne
@ManyToMany
@NotFound

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     hibernate   annotations


 Q3. What is the use of @GeneratedValue annotation in Hibernate?Hibernate
Ans. This annotation is added to the auto increment column with the strategy to increment the column value. Usually this is added to the surrogate primary key column and specified with the Database Sequence.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     hibernate   hibernate annotations   @generatedvalue   database sequence


 Q4. Give an Example of Annotations ?
Ans. Suppose that a software group traditionally starts the body of every class with comments providing important information:
public class Generation3List extends Generation2List {

// Author: John Doe
// Date: 3/17/2002
// Current revision: 6
// Last modified: 4/12/2004
// By: Jane Doe
// Reviewers: Alice, Bill, Cindy

// class code goes here

}
To add this same metadata with an annotation, you must first define the annotation type. The syntax for doing this is:
@interface ClassPreamble {
String author();
String date();
int currentRevision() default 1;
String lastModified() default "N/A";
String lastModifiedBy() default "N/A";
// Note use of array
String[] reviewers();
}
The annotation type definition looks similar to an interface definition where the keyword interface is preceded by the at sign (@) (@ = AT, as in annotation type). Annotation types are a form of interface, which will be covered in a later lesson. For the moment, you do not need to understand interfaces.
The body of the previous annotation definition contains annotation type element declarations, which look a lot like methods. Note that they can define optional default values.
After the annotation type is defined, you can use annotations of that type, with the values filled in, like this:
@ClassPreamble (
author = "John Doe",
date = "3/17/2002",
currentRevision = 6,
lastModified = "4/12/2004",
lastModifiedBy = "Jane Doe",
// Note array notation
reviewers = {"Alice", "Bob", "Cindy"}
)
public class Generation3List extends Generation2List {

// class code goes here

}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   annotations


 Q5. What are few of the Annotations pre defined by Java?
Ans. @Deprecated annotation indicates that the marked element is deprecated and should no longer be used. The compiler generates a warning whenever a program uses a method, class, or field with the @Deprecated annotation.

@Override annotation informs the compiler that the element is meant to override an element declared in a superclass.

@SuppressWarnings annotation tells the compiler to suppress specific warnings that it would otherwise generate.

@SafeVarargs annotation, when applied to a method or constructor, asserts that the code does not perform potentially unsafe operations on its varargsparameter. When this annotation type is used, unchecked warnings relating to varargs usage are suppressed.

@FunctionalInterface annotation, introduced in Java SE 8, indicates that the type declaration is intended to be a functional interface, as defined by the Java Language Specification.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   java8   annotations   pre defined annotations


 Q6. What are meta Annotations ?
Ans. Annotations that apply to other annotations are called meta-annotations.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   annotations   meta annotations


 Q7. Name few meta-annotations ?
Ans. @Retention annotation specifies how the marked annotation is stored:

@Documented annotation indicates that whenever the specified annotation is used those elements should be documented using the Javadoc tool. (By default, annotations are not included in Javadoc.)

@Target annotation marks another annotation to restrict what kind of Java elements the annotation can be applied to.

@Inherited annotation indicates that the annotation type can be inherited from the super class. (This is not true by default.) When the user queries the annotation type and the class has no annotation for this type, the class' superclass is queried for the annotation type. This annotation applies only to class declarations.

@Repeatable annotation, introduced in Java SE 8, indicates that the marked annotation can be applied more than once to the same declaration or type use. For more information, see Repeating Annotations.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   java8   annotations   meta annotations


 Q8. How to create a Junit to make sure that the tested method throws an exception ?
Ans. Using annotation Test with the argument as expected exception.

@Test (expected = Exception.class)

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     junit   junit annotations


 Q9. What is the use of Deprecated annotation ?
Ans. Deprecated annotation is for documentation purpose only. It doesn't enforce anything but would mark the method name as crossed to signify that the client should refrain from using it.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     Deprecated annotation


 Q10. Does Deprecated annotation enforces anything ?
Ans. No. It just marks the method and hence signals the client to refrain from using it.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     Deprecated annotation


 Q11. Explain Annotations ?
Ans. Annotations, a form of metadata, provide data about a program that is not part of the program itself. Annotations have no direct effect on the operation of the code they annotate. Annotations have a number of uses, among them:
• Information for the compiler — Annotations can be used by the compiler to detect errors or suppress warnings.
• Compile-time and deployment-time processing — Software tools can process annotation information to generate code, XML files, and so forth.
• Runtime processing — Some annotations are available to be examined at runtime.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   annotations      basic        frequent


 Q12. What entries we make in the hibernate config file if we are not using hbm files but Annotations ?Hibernate
Ans. We configure Entity classes having annotated mappings.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     hibernate   hibernate annotations


 Q13. What is the difference between these 2 annotations ?

@Entity

@Entity ( name="EMPLOYEES" )
Hibernate
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".

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     hibernate   hibernate annotations   entity annotations


 Q14. What is the difference between these 2 annotations ?

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

@Entity ( name="EMP")
@Table ( name="EMPLPYEES" )
Hibernate
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.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     hibernate   hibernate annotations   entity annotation   table annotation


 Q15. What are the different ID generating strategies using @GeneratedValue annotation ?Hibernate
Ans. Auto , Identity , Sequence and Table.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     hibernate   generatedvalue annotations   architecture


 Q16. How to do Eager loading in Hibernate ?Hibernate
Ans. Using

lazy = false in hibernate config file

or

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

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     hibernate   lazy loading hibernate   basic annotation hibernate   architecture


 Q17. What are the annotations used in Junit with Junit4 ?
Ans. @Test

The Test annotation indicates that the public void method to which it is attached can be run as a test case.

@Before

The Before annotation indicates that this method must be executed before each test in the class, so as to execute some preconditions necessary for the test.

@BeforeClass

The BeforeClass annotation indicates that the static method to which is attached must be executed once and before all tests in the class.

@After

The After annotation indicates that this method gets executed after execution of each test.

@AfterClass

The AfterClass annotation can be used when a method needs to be executed after executing all the tests in a JUnit Test Case class so as to clean-up the set-up.

@Ignores

The Ignore annotation can be used when you want temporarily disable the execution of a specific test.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   junit   jnuit4   junit annotations


 Q18. Name few annotations related classes and interfaces ?
Ans. http://www.buggybread.com/2015/01/java-annotations-classes-and-interfaces.html

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   annotations


 Q19. What is the difference betweeen @Inject and @Autowired ?Spring
Ans. @Autowired and @Inject are similar in terms of functionality they achieve. @Inject is part of a new Java technology called CDI that defines a standard for dependency injection whereas @Autowired is a Spring specific annotation for dependency injection.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     spring   web frameworks   dependency injection   autowired   inject   spring annotations   ioc


 Q20. If you are supposed to deprecate the method , Will you deprecate the method in the implementation class or will you deprecate the abstract declaration within interface or abstract class ?
Ans. Deprecating the interface / or declaration doesn't make much sense as the implementation is deprecated and not the interface.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     Deprecated annotation


 Q21. What is the use of Annotations in Java ?Core Java
Ans. Annotations are used to specify meta information about the code.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     Annotations


 Q22. Are Annotations better than using XML configs ?Core Java
Ans. Yes , as both code and its meta information reside in the same file, it promotes better readability and maintenability.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     Annotations


 Q23. What is the use of @Bean annotation in Spring ?Spring
Ans. There are 2 ways to specify dependencies in Spring, one by the way of specifying beans in config files and other is by specifying annotations like @Bean, @Component , @Service etc to let spring know of the dependencies.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     spring bean annotation  spring annotations


 Q24. What is the use of @Import and @ImportResource anotations ?
Ans. The @Import annotation is used to import one or more @Configuration classes. This annotation provides the functionality equivalent to element in xml based configuration.

The @ImportResource annotation is used to import one or more XML configuration files.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     annotations     Asked in 1 Companies


 Q25. What are custom annotations and How can we create one ?Core Java
 This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     annotations  custom annotations      basic


 Q26. How did you use Spring in your project ? Which Spring annotations have you used in your project ?Spring
Ans. @RequestMappping

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     spring  spring annotations     Asked in 1 Companies


 Q27. What is stereotype annotation ?Spring
Ans. These annotations are used to create Spring beans automatically in the application context. The main stereotype annotation is @Component . @Controller: Which is used to create Spring beans at the controller layer. The stereotype annotations in spring are @Component, @Service, @Repository and @Controller

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     stereotype annotation   stereotype annotation spring     Asked in 1 Companies


 Q28. what is dispatcher servlet@componentScan use ?Spring Framework
Ans. @ComponentScan in a Spring Application.

With Spring, we use the @ComponentScan annotation along with the @Configuration annotation to specify the packages that we want to be scanned. @ComponentScan without arguments tells Spring to scan the current package and all of its sub-packages.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     ComponentScan  dispatcher  @ComponentScan annotation  @Configuration annotation     Asked in 1 Companies


 Q29. Which of following annotation is used to initialize objects before executing set of tests ?Junit
a. @Test
b. @Ignore
c. @After
d. @Before

Ans.d. @Before

 Q30. Which of the following is not an Hibernate AnnotationHibernate
a. @Id
b. @JoinTable
c. @ManyToMany
d. @Autowired

Ans.d. @Autowired


Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked: