Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

Hibernate

Q1.What is one of the basic requirement for an ORM solution ?choose the most
appropriate answer?
1.Should have API for performing Select,Insert,Update,Delete operations on
object of persistent classes.
2.Should have API for performing Create,Read,Update,Delete operations on
object of persistent classes.
3.Should have API for performing Read,Upadte,,Delete,Search operations on
object of persistent classes.
4.Should have API for performing Read,Insert,Update,Search operations on
object of persistent classes.

Q2.Which of the following is Not a core interface of Hibernate framework?


1.Session Interface
2.SessionFactory interface
3.Query and Criteria interface
4.Mapping interface.

Q3.In Hibernate which is a single threaded short lived object that is used by
application to specify atomic units of work
1.Transaction
2.Session
3.Session Factory
4.query

Q4.In hibernate the file hibernate.cfg.xml provides


1.Details needed to connect to the database
2.All tables information
3.All class and property information
4.Oracle jars files

Q5.In Hibernate if the mapping filename is A.hbm.xml, how do u specify the


mapping file detailsin the hibernate.cfg.xml?
1.<mapping files=”A.hbm.xml”/>
2.<resource mapping=”A.hmb.xml”/>
3.<map resources=”A.hbm.xml”/>
4.<mapping resources=”A.hbm.xml”/>

Q6.which one the following is not the method of session interface


1.save
2.delete
3.drop
4.update
Q7.What is true about session.get() method and session.load() method while
retriviong data in hibernate?
1.if the required object is not in the database then the method
ssession.load(..)throws an exception…

Q8.what does session.flush() do ?


1.the state of that object will be synchronized with the database
2.the state of that object will be synchronized with the SessionFactory
3.remove state of that object from session
4. remove state of that object from sessionFactory.

Q9.In hibernate which is Not a valid instance state


1.transient
2.persistent
3.detached
4.volatile

Q10.in hibernate to transit an object from transient state to persistent


state which method can be used?
1.delete()
2.persist()
3.push()
4.save()

Q11.In Hibernate mapping file which element is used for identifier mapping
and generation
1.<column>
2.<property>
3.<id>
4.<identifier>

Q12.in hibernate If u want to automatically generate the key value of “id”


element instead of u manually setting it done by which statement ?
1.<generator class=”assigned”
2.<id name=”id” column=”sid” type=”int” generator=”increment”/>
3.<generator class=”increment”/>
4.<id=”name” column=”sid” type=”int” generator=”assigned”/>

Q13.in case of bi-directional associations which attributes is required to


establish the association ?
1.parent=”true”
2.inverse=”false”
3.inverse=”true”
4.key=”false”
Q14.in hibernate if there is one to many relation between the “Actor” and
“Movie” how will mapping for the set “movies” look in “Actor.hbm.xml”
1.<set name=”movies” cascade=”save-update”><key column=”ACTORID”/><one-to-
many class=”Movie”/></set> //set name is movies in question having
actorid as key (1 Actor set of movies)
2. <set name=”movies” cascade=”save-update”><key column=”MOVIEID”/><one-to-
many class=”Movie”/></set>
3. <set name=”actor” cascade=”save-update”><key column=”ACTORID”/><one-to-
many class=”Movie”/></set>
4.<set name=”actor” cascade=”save-update”><key column=” MOVIEID”/><one-to-
many class=”Actor”/></set>
Q15.which collection type in hibernate does not have indices
1.array
2.bag
3.list
4.map

Q16.in hibernate association mapping can be


1.only unidirectional
2.only bidirectional
3.unidirectional as well as bidirectional
4.neither unidirectional nor bidirectional

Q17.Which of the following is true w.r.t HQL ?


1.HQL allows representing SQL queries in object oriented terms by using
object and properties of object
2.HQL fully supports polymorphic queries
3.HQL contains advanced features such as pagination,fetch join with dynamic
profiling and so forth.
4.All of the above

Q18.in hibernate ,if u need to assign aliases to the classes in ur HQL ,how
do u assign and create query ?
1. 1.String hql=”From employee Alias of Employee”;
Query q=session.createAliasQuery(hql);
2. 1.String hql=”From employee as emp”;
Query q=session.createQuery(hql);
3. 1.String hql=”Alias emp From Employee”;
Query q=session.createQuery(hql);
4..String hql=” Employee Alias From emp ”;
Query q=session.createAliasQuery(hql);
Q19.Suppose u want to accept an input from the user say “employee_id” and
query the details of “employee_id “ how do u write query in HQL
1.String hql=”FROM employee emp where emp.id=:employee_id”;
Query q=session.createQuery(hql);
q.setParameter(“employee_id”,101);
List results=query.list(); //There is nothing called
“Alias” in query language dont choose those answers…
2. String hql=”FROM emp Alias of Employee where emp.id=:employee_id”;
Query q=session.createQuery(hql);
q.setNamedParameter(“employee_id”,101);
List results=query.list();

Q20.Suppose u want to find the maximum mark in “Student”, how do u write a


query in HQL ?
1.String hql=”Select max(s.mark) From Student s”; //aggregate
function max in Query.
Query query=session.createQuery(hql);
List results=query.list();
2.String hql=”select maximum(s.mark)……
blah blah blah
3. String hql=”select maxvalues(s.mark)……
blah blah blah
4. String hql=”select maxdata(s.mark)……
blah blah blah

Q21.In hibernate which of the following is a mapping for a class having a


reference to another class as a member variable ?
1.Class Mapping
2.Association Mapping
3.Component Mapping
4.Reference Mapping

Q22.In Hibernate which of the collections types cannot store indices ?


1.List
2.Set //Set and Bag doesn’t store indices
3.Map
4.Array
Q23.In Hibernate ,consider the following
<class name=”Person”>
<id name =”id” column=”personid”>
<generator class=”native”/>
</id>
</class>
<class name=”Address”>
<id name=”id” column=”personid”>
<generator class=”foreign”>
<param-name=”property”>person</param>
</generator>
</id>
<one-to-one name=”person” constrainted=”true”/>
</class>

Above code is an example of


1.unidirectional one-to-one association
2. unidirectional one-to-many association
3. unidirectional many-to-one association
4. multidirectional many-to-one association

Q24.In hibernate whenever a parent object is persisted ,if u need the child
object also to get automatically persisted which is the correct statement ?
1.<set name=”xxx” sabe-update=”cascade”>
2.<set name=”xxx” cascade=”save-update”>
3.<set name=”xxx” unsaved-value=”0”>
4.<set name=”xxx” class=”child”/>

Q25.In hibernate mapping file,what should be generator class strategy of


id,if u want client application itself to assign the id ?
1.<generator class =”increment”/>
2.<generator assigned=”true” />
3.<generator class=”assigned”/>
4.<generator class=”application”/>

Q26.In hibernate which one of the following will be detached and free to use
in any application layer when session is closed ?
1.Transaction
2.Session.
3.SessionFactory
4.Persistence objects
Q27.How can u get a session object ?
1.SessionFactory.getSession();
2.SessionFactory.openSession();
3.SessionFactory.get(); //Doubt
4.(session)SessionFactory.getObject();

Q28.How is session opened in Hibernate?


1.Session s=SessionFactory.openSession(); //Doubt
2.SessionFactory sf=new Configuration().buildSessionFactory();Session
s=sf.openSession();
3. SessionFactory sf=new
Configuration().configure().buildSessionFactory();Session s=sf.openSession();
4.Session s=new SessionFactory().openSession();

Q29.In hibernate ,which file does the database connection related information
are specified ?
1.Dialects file
2.hibernate.hbm.xml file
3.hibernate.cfg.xml
4.application.xml.cfg

Q30.Which one of the following statements is true about Session Interface in


hibernate ?
1.Does not act as persistence manager
2.They are thread safe
3.Session instances are got from SessionFactory
4.Specifies the location of mapping documents

Q31.Which one of the following is true about hibernate?


1.Hibernat allows object reation mapping and provides persistence to objects
2.hibernate does not support java collection framework
3.does not provide data query= and retrieval facilities
4.hibernate significantly increases the development time

Q32.Hibernate is an ORM solution,what does ‘R’ stands for ?


1.Rational
2.Relative
3.Relational
4.Readable

Q33.In Hibernate, L2 cache is maintained per?


A: Query
Q34.In Hibernate, by default which cache is enabled?
A: First level cache

Q35. add a restriction to return the records with salary is equal to 2000
A: Criteria cr = session.createCriteria(Employee.class);
cr.add(Restrictions.eq("salary", 2000));
List results = cr.list();
--------------------------------------------------------------
Criteria cr = session.createCriteria(Employee.class);

// To get records having salary more than 2000


cr.add(Restrictions.gt("salary", 2000));

// To get records having salary less than 2000


cr.add(Restrictions.lt("salary", 2000));

// To get records having fistName starting with zara


cr.add(Restrictions.like("firstName", "zara%"));

// Case sensitive form of the above restriction.


cr.add(Restrictions.ilike("firstName", "zara%"));

// To get records having salary in between 1000 and 2000


cr.add(Restrictions.between("salary", 1000, 2000));

// To check if the given property is null


cr.add(Restrictions.isNull("salary"));

// To check if the given property is not null


cr.add(Restrictions.isNotNull("salary"));
// To check if the given property is empty
cr.add(Restrictions.isEmpty("salary"));

// To check if the given property is not empty


cr.add(Restrictions.isNotEmpty("salary"));
--------------------------------------------------------------
Q36. Identify two methods of the Criteria interface for pagination
A: 1 public Criteria setFirstResult(int firstResult)
This method takes an integer that represents the first row in your result
set, starting with row 0.
2 public Criteria setMaxResults(int maxResults)
This method tells Hibernate to retrieve a fixed number maxResults of objects.
Q37. findDirty()
This method is be called when the flush() method is called on a Session
object.
Q38. onFlushDirty()
This method is called when Hibernate detects that an object is dirty (ie.
have been changed) during a flush i.e. update operation.

You might also like