Hibernate 5.1.0 Fiverr Skills Test

Which of the following Hibernate cache modes does not read from cache but writes to cache upon loading from the database?

CacheMode.REFRESH

CacheMode.GET

CacheMode.NORMAL

CacheMode.PUT

In Hibernate, what will happen if the requested lock mode is NOT supported by the database?

Hibernate will throw an exception.

Hibernate will use an appropriate alternate locking mode.

Hibernate will cause an application failure/halt.

Hibernate will cause transaction rollback.

The "markRollbackOnly" method provided by the Hibernate Transaction API works in which of the following environments?

JTA

JDBC

Both JTA and JDBC

Which of the following is the correct syntax to instruct Hibernate to store the Strings as nationalized data?

@org.hibernate.annotations.Type("nstring")

private String p_name

@org.hibernate.annotations.Type("materialized_nclob")

private String p_description;

@org.hibernate.annotations.Type( type String p_ name = "nstring")

private String p_ name;

@org.hibernate.annotations.Type(type String p_description = "materialized_nclob")

private String p_description;

@org.hibernate.annotations.Type(String p_ name = type nstring)

private String p_ name; @org.hibernate.annotations.Type(String p_description = type materialized_nclob)

private String p_description;

@org.hibernate.annotations.Type(type = "nstring")

private String p_ name;

@org.hibernate.annotations.Type(type = "materialized_nclob")

private String p_description;

Which of the following methods must be regularly employed to a session to control the size of first-level cache when any new object is made persistent during Hibernate batching?

flush()

commit()

scroll()

clear()

delete()

Which of the following options of special case–qualified path expressions is/are valid for both Maps and Lists?

INDEX

KEY

ENTRY

All of the above

Which of the following is a way of overriding the 'EAGER' fetching association at runtime?

Queries

No fetching

Entity graphs

Batch

Choose True or False.

Hibernate uses JDBC connections and JTA resources indirectly, alongside adding additional locking behavior.

True

False

Which of the following options is correct about 'String' strategy used for storing enum values?

Enum values are stored according to enum value's ordinal position within the enum class, as indicated by java.lang.Enum#ordinal.

Enum values are stored according to the enum value's name, as indicated by java.lang.Enum#name.

Enum values are stored according to enum value's ordinal position and enum value's name within the enum class, as indicated by java.lang.Enum#ordinal.

None of the above.

Which of the following options are stored by the Date class of Hibernate?

i)Hours

ii)Months

iii)Days

iv)Nanoseconds

v)Years

Only options ii) and v)

Only options i), ii) and iv)

Only options ii), iii) and v)

All of the given five options are stored by the Date class of Hibernate

Which of the given options is correct about the following Java class names in Hibernate?

1.org.hibernate.abc.CHECK

2.org.hibernate.abc.Check

Both class names are same because HQL is case-insensitive.

The given two class names represent different Java classes as Java class names are case-sensitive in HQL

Only the first Java class declaration is correct because a class name should always be in uppercase in HQL.

Only the second Java class declaration is correct because a class name should always be in lowercase in HQL.

For physical transactions, what should be done for reducing the lock contention in a database?

Execute only one physical transaction in an hour.

Execute only one particular type of physical transaction at a time.

The physical database transactions should be kept as short as possible.

The number of physical database transactions should be kept as less as possible.

Which of the following is the first Hibernate object that is created in any Hibernate application?

SessionFactory object

Session object

Configuration object

Criteria object

Which of the following codes should be applied by a project to use the Gradle plugin?

ext {

hibernateVersion = 'Any-hibernate-version-you-like'}

buildscript {

dependencies {

classpath "org.hibernate:hibernate-gradle-plugin:$hibernateVersion"

} }

Hibernate {

enhance {

// your configuration

} }

@Entity {

hibernateVersion = 'Only-the-current-hibernate-version'}

buildscript {

getEntityManagerFactory {

classpath "org.hibernate:hibernate-gradle-plugin:$hibernateVersion"

} }

hibernate {

build {

// your configuration

} }

ext {

hibernateVersion = 'Any-hibernate-version-you-like'}

buildscript {

dependencies {

@Entity{

classpath ('org.hibernate:hibernate-gradle-plugin:$hibernateVersion');

} }

hibernate {

build {

// your configuration

} } }

None of the codes is correct

Using Hibernate Query Language, which of the following syntax will return the records from 4th to 12th numbered positions, from a class named "Employee"?

Query q=session.createQuery("from Employee");

q.setFirstResult(4);

q.setMaxResult(12);

List list=q.list();

Query q=session.Query("Employee");

q.setParamater(4, 12);

List list=q.list();

Query q=session.createQuery("Employee");

q.setFirstParamater(4);

q.setMaxParamater(12);

List list=q.executeUpdate(); ();

Query q=session.q("from Employee");

q.setFirstResult("4");

q.setMaxResult("12");

List list=q.list();

Which of the following Hibernate interfaces is responsible for providing callbacks from session to the application and allowing applications to inspect and/or manipulate the properties of a persistent object before the object is saved, updated, deleted or loaded?

org.hibernate.Query

org.hibernate.engine.HibernateIterator

org.hibernate.cfg.Configuration

org.hibernate.Interceptor

Which of the following options holds true for the hibernate.jdbc.batch_versioned_data setting, when your JDBC driver returns incorrect row count when a batch is executed?

In this situation, hibernate.jdbc.batch_versioned_data settings should not be used.

In this situation, the value of hibernate.jdbc.batch_versioned_data should be set to true.

In this situation, the value of hibernate.jdbc.batch_versioned_data should be set to false.

None of the above.

In Hibernate, which of the following lock levels of the LockMode class is automatically acquired when Hibernate updates or inserts a row?

LockMode.UPGRADE_SKIPLOCKED

LockMode.UPGRADE

LockMode.NONE

In Hibernate, which of the following are the correct syntax for defining an entity?

@Entity

public class MyProduct {

#basic

@p_Id private Integer p_id;

private String p_name;

private String p_descrptn;

})

#Entity

public class MyProduct {

#p_Id

#basic

private Integer p_id;

#basic

private String p_name;

#basic

private String p_descrptn;

}

@Entity

public class MyProduct {

@p_Id

@Basic

private Integer p_id;

@Basic

private String p_name;

@Basic

private String p_descrptn;

}

@Entity

public class MyProduct {

@p_Id

private Integer p_id;

private String p_name;

private String p_descrptn;

}

Which of the following statements correctly explains the concept of transactional write-behind in Hibernate?

In transactional write-behind, a transaction is opened after the end-user-level work is finished and is not opened during end-user-level work.

In transactional write-behind, a transaction is opened during the end-user-level work and is closed after end-user-level work is finished.

In transactional write-behind, a transaction is opened before the end-user-level work begins and is left open afterwards.

In transactional write-behind, a transaction is opened before the end-user-level work begins and is closed once the end-user-level work is finished.

Which of the following syntax will explicitly map 'p_name' attributes to 'chk_names' column, as opposed to the implicit column name 'p_name'?

@Entity

public class MyProduct {

@p_Id

@Basic

private Integer p_id;

@Basic

@Column

(private String p_name = "chk_names");

@Basic

private String p_descrptn;

}

@Entity

public class MyProduct {

@p_Id

@Basic

private Integer p_id;

@Basic

@Column (p_name = "chk_names")

private String p_name;

@Basic

private String p_descrptn;

}

#Entity

public class MyProduct {

#p_Id

#Basic

private Integer p_id;

private String p_name;

#Column

p_name = 'chk_names';

private String p_descrptn;

}

None of these

Which two of the following files are used by a Hibernate Configuration object to handle database connection?

hibernate.properties

hbm.xml

persistence.xml

hibernate.cfg.xml

Which of the following is the correct syntax for creating a TypedQuery for a class named "Employee" with attribute "name"?

TypedQuery <Employee> = entityManager.createQuery(

"select e from Employee e where e.name like :name",

Employee.class

)

TypedQuery <Employee> typedQuery = entityManager.createQuery(

"select e " +

"from Employee e " +

"where e.name like :name", Employee.class

);

TypedQuery typedQuery("Employee") = entityManager.createQuery(

"select e "

"from Employee e "

"where e.name like :name", Employee.class

);

TypedQuery("Employee").typedQuery = entityManager.createQuery(Employee.class

'select e' +

'from Employee e' +

'where e.name like "name" '

);

In Hibernate, which of the following caching configuration properties is used for enabling and disabling second-level caching for query results?

hibernate.cache.use_second_level_cache

hibernate.cache.query_cache_factory

hibernate.cache.region_prefix

hibernate.cache.use_query_cache

Which of the following APIs represent(s) a context for dealing with persistence data?

org.hibernate.resource.transaction.TransactionCoordinator

org.hibernate.Session

javax.persistence.EntityManager

javax.persistence.Query

In Hibernate, which of the following is the correct syntax of the configuration property that is required to be enabled in order to use query caching?

<property name="hibernate.cache.query_cache_factory" value="true"/>

<property "hibernate.cache.query_cache_factory" ="true"/>

<set property "hibernate.cache.use_query_cache" value="true"/>

<property name="hibernate.cache.use_query_cache" value="true"/>

Which of the following statements is correct about StatelessSession during Hibernate batching?

It provides first-level cache.

It is used for streaming data to and from the database in the form of detached objects.

It supports interaction with any second-level or query cache.

It supports transactional write-behind or automatic dirty checking.

Which of the following is the correct syntax of the method used for accessing Hibernate APIs from JPA?

Session session = entityManager.StandardServiceRegistry.unwrap(Session.class);

SessionImplementor sessionImplementor = StandardServiceRegistry.unwrap( SessionImplementor.class);

SessionFactory sessionFactory =getEntityManagerFactory().unwrap(SessionFactory.class);

Session session = StandardServiceRegistry.unwrap(Session.class);

SessionImplementor sessionImplementor = StandardServiceRegistry.unwrap(SessionImplementor.class);

SessionFactory sessionFactory = StandardServiceRegistry.getEntityManagerFactory().unwrap(sessionFactory.class);

Session session = entityManager.unwrap(Session.class );

SessionImplementor sessionImplementor = entityManager.unwrap(SessionImplementor.class);

SessionFactory sessionFactory = entityManager.getEntityManagerFactory().unwrap(SessionFactory.class );

Session session = Persistance.StandardServiceRegistry.unwrap(Session.class );

SessionImplementor sessionImplementor = StandardServiceRegistry.unwrap( SessionImplementor.class);

SessionFactory sessionFactory = StandardServiceRegistry().unwrap.sessionFactory.class();

Carefully analyze the following code snippet and answer the given question.

@Entity

public class Employee {

@Enumerated

public Gender gender;

public static enum Gender {

MALE,

FEMALE

} }

Which of the following values will be stored in the gender column?

NULL - null

0 - MALE

1 - FEMALE

MALE - MALE

FEMALE - FEMALE

Consider the following Hibernate natural id entity mapping and answer the given question.

@Entity(name = "Employee")

@Cacheable

@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)

public static class Employee {

@Id

@GeneratedValue(strategy = GenerationType.AUTO)

private Long id;

private String name;

@NaturalId

@Column(name = "code", unique = true)

private String code;

public Employee() {}

public Employee(String name) {

this.name = name; }

public Long getId() {

return id; }

public String getName() {

return name; }

public void setName(String name) {

this.name = name; }

public String getCode() {

return code; }

public void setCode(String code) {

this.code = code; }

}

Which of the following is the correct syntax for loading the entity using Hibernate native natural id API?

Employee employee = session

.byNaturalId(Employee.class.)

.using("code", "unique-code")

.load();

Employee employee = session.load(

.byNaturalId(Employee.class.cache)

.using("code", "unique-code"))

Employee employee = session

.byNaturalId(Employee.class.load())

.using(unique-code("code"))

Employee employee = load(

session

.byNaturalId(Employee.cache)

.using(unique-code("code"))

Which of the following is the correct HQL syntax for obtaining the highest salary of an employee from the "emp_records" class?

Query qry=session.createQuery("select max(salary) from emp_records");

Query qry=session.createQuery("select maximum salary from emp_records");

Query qry=session.createQuery("select salary(max) from emp_records");

Query qry=session.createQuery("select salary(maximum) from emp_records");

Which of the following Hibernate parameters defines which org.hibernate.context.spi.CurrentSessionContext implementation should be used by the contextual sessions?

hibernate.current_session_context_class

org.hibernate.Session

org.hibernate.SessionFactory

hibernate.integrator_provide

Which of the following options is/are introduced during Hibernate fetching so that the application developer has more control over fetch plans?

Fetch profiles

Entity graphs

HQL

Queries

Hibernate uses which of the following objects to create a SessionFactory object?

Session object

Configuration object

Transaction object

Query object

In Hibernate, which of the following is NOT a valid value for the hibernate.cache.default_cache_concurrency_strategy property of caching configuration?

transactional

write-only

read-only

read-write

nonstrict-read-write

In Hibernate, which of the following options can manage transactions via calls to java.sql.connection?

jdbc

jta

Both jdbc and jta

Neither Jdbc nor jta

Which of the following options correctly differentiates between optimistic and pessimistic locking strategy in Hibernate?

The optimistic locking approach proceeds without locking the data resources that the transactions affect, whereas the pessimistic locking approach requires the data resources to be locked after they are read and only unlock them after the application has finished using the data.

The optimistic locking approach locks the data resources for a certain period of time and releases them after that, irrespective of whether or not the application has finished using the data, whereas the pessimistic locking approach requires the resources to be locked until the application has finished using them.

The optimistic locking approach locks the data resources till the application has finished using them, whereas the pessimistic locking proceeds without locking the data resources that the transactions affect.

The optimistic locking approach requires the data resources to be locked after they are read and only unlock them after the application has finished using the data, whereas the pessimistic locking approach locks the data resources for a certain period of time and releases them after that time, irrespective of whether or not the application has finished using the data.

A SessionFactory object is created during which of the following stages of an application life cycle?

During application startup

During application runtime

After the application ends

Anytime during the application life cycle

In Hibernate, 'org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform' exposes access to which of the following?

javax.persistence.Query

javax.transaction.UserTransaction

javax.persistence.criteria.CriteriaQuery

javax.transaction.Synchronization

javax.transaction.TransactionManager

For which of the following values of second-level cache mapping, entities are always cached even if they are marked as non-cacheable?

ENABLE_SELECTIVE

ALL

NONE

DISABLE_SELECTIVE

How many SessionFactory objects are required per database while using a separate file?

One

Two

Three

Four

In which of the following implementations of 'org.hibernate.context.spi.CurrentSessionContext', the current sessions are tracked by thread of execution, but the user is responsible for binding and unbinding a session instance with static methods on this class?

org.hibernate.context.internal.JTASessionContext

org.hibernate.context.internal.ThreadLocalSessionContext

org.hibernate.context.internal.ManagedSessionContext

Both options a and b

In Hibernate, what is the default value for the configuration settings: enableLazyInitialization, enableDirtyTracking and enableAssociationManagement available with Gardle plugin?

It is true for all three: enableLazyInitialization, enableDirtyTracking and enableAssociationManagement.

It is false for all three: enableLazyInitialization, enableDirtyTracking and enableAssociationManagement.

It is true for enableLazyInitialization but false for enableDirtyTracking and enableAssociationManagement.

It is true for enableLazyInitialization and enableDirtyTracking but false for enableAssociationManagement.

Which of the following is the correct syntax for making an entity persistent with Hibernate API?

Employee emp = new Employee();

emp.e_Id{1L };

emp.e_Name{' Paul Walker'};

session.save( Employee emp);

Employee emp = new Employee();

emp.e_Id{1L };

emp.e_Name{' Paul Walker'};

entityManager.session.save( Employee emp);

Employee emp = new Employee();

emp.e_Id( 1L );

emp.e_Name("Paul Walker");

entityManager.save("emp");

Employee emp = new Employee();

emp.e_Id( 1L );

emp.e_Name("Paul Walker");

session.save( emp);

Which of the following options is/are first built in native bootstrapping and which hold(s) the services needed by Hibernate during bootstrapping and at run time?

SessionFactory

EntityManagerFactory

ServiceRegistry

Both options a and b

Which of the following is the correct syntax for an HQL update query that will update e_name to Mark, where e_id is 20 for a class named "Employee"?

Transaction txn=session.beginTransaction();

Query qry=session.createQuery("update User set e_name=n where e_id=i");

qry.setParameter(n,"Mark");

qry.setParameter(i, "20");

int sts=qry.executeUpdate();

System.out.println(sts);

qry.commit();

Transaction txn=session.beginTransaction(

Query qry=session.createQuery(update User set e_name= "n" where e_id= "i");

qry.setParameter("n = Mark");

qry.setParameter("i = 20");

int sts= executeUpdate(qry);

System.out.println(qry);

sts.commit(); );

Transaction txn=session.beginTransaction();

Query qry=session.createQuery("update User set e_name=:n where e_id=:i");

qry.setParameter("n","Mark");

qry.setParameter("i",20);

int sts=qry.executeUpdate();

System.out.println(sts);

txn.commit();

Transaction txn=session.beginTransaction{

Query qry=session.createQuery(update User set e_name= ":n" where e_id= ":i");

qry.setParameter(n,"Mark");

qry.setParameter(i,20);

int sts=qry.executeUpdate();

System.out.println(qry);

sts.commit(); };

In Hibernate, what is the result type of aggregate function, COUNT?

Integer

Double

Long

It is same as the argument type

In Hibernate, when does the auto flushing mode flush the session?

It flushes the session only if necessary.

It flushes the session before every query.

It flushes the session after five queries.

It delays the flushing until the current transaction is committed.

In Hibernate, applications do not have to explicitly configure a ConnectionProvider because Hibernate internally determines which ConnectionProvider to use. Which of the following options, if set, takes precedence while determining the ConnectionProvider?

hibernate.proxool

hibernate.connection.datasource

hibernate.connection.provider_class

hibernate.connection.url

In Hibernate, during which of the following states, an entity has an associated identifier but it is no longer associated with a persistence context?

Removed

Detached

Transient

Managed

In Hibernate, which of the following commands can be used for removing an entity "emp" with JPA?

entityManager.delete( "emp");

entityManager.session.remove(emp);

entityManager.remove(emp);

entityManager.session.delete("emp");

For the JPA applications, the hibernate.connection.datasource corresponds to which two of the following options?

hibernate.connection.provider_class

javax.persistence.jtaDataSource

hibernate.connection.url

javax.persistence.nonJtaDataSource

Which of the following cache regions is responsible for holding cached query results?

org.hibernate.cache.spi.UpdateTimestampsCache org.hibernate.cache.internal.StandardQueryCache

org.hibernate.cache.spi.RegionFactory

org.hibernate.cache.spi.QueryCacheFactory

For which of the following lock modes, a version number check is performed by the Session.lock() method?

Read

Write

UPGRADE_NOWAIT

UPGRADE_SKIPLOCKED

None

Which of the following is the correct syntax for HQL-style Hibernate positional parameter binding for a class named "Employee" with "e_name" field?

Query qry= session.createQuery(

"select e #

from Employee e #

where e.e_name like &")

.setParameter(J% );

org.hibernate.Query qry = session.createQuery(

"select e " +

"from Employee e " +

"where e.e_name like ? " )

.setParameter( 0, "J%" );

org.hibernate.Criteria ctr=session.createCriteria (

'select e +

from Employee e +

where e.e_name like %')

.setParameter("0, J%");

Query qry = session.createQuery(

'select e' +

'from Employee e' +

'where e.e_name like J%')

.setParameter( 0, "J%" );

In Hibernate, which of the following utilities allows bootstrapping the JPA environment even in the absence of persistence.xml configuration file?

EntityManagerFactoryBuilderImpl

PersistenceUnitInfoDescriptor

integrationSettings

None of the above

Which of the following Hibernate plugin support(s) the configuration setting, failOnError?

Gradle plugin

Maven plugin

Both Gradle and Maven plugins

Neither Gradle nor Maven plugin

Which of the following is the correct syntax of the Hibernate method used to obtain an entity reference with its data initialized with JPA? Consider an entity Employee emp with e_id and e_name.

Employee emp = entityManager.get( Employee.class).load(e_Id);

Employee emp = entityManager.find( Employee.class, e_Id);

Employee emp = entityManager.load( Employee.class.e_Id);

Employee emp = entityManager.find.get( Employee.class,("e_Id") );

By reading the value of which of the following annotations, the timestamp value from the database or the JVM can be retrieved by Hibernate?

@org.hibernate.annotations.Source

@org.hibernate.annotations.Cache

@org.hibernate.annotations.Polymorphism

@org.hibernate.annotations.Type

Which of the following is the correct HCQL syntax to get those records from "emp_record" class where the "salary" is greater than $5000?

Criteria ctr=session.createCriteria("emp_record");

ctr.add(Restrictions(salary>5000));

List my_list=ctr.my_list();

Criteria ctr=session.createCriteria(class.emp_record);

ctr.add(Restrictions.gt("salary, 5000"));

List my_list= my_list(ctr);

Criteria ctr=session.createCriteria(emp_record.class);

ctr.add(Restrictions.gt("salary",5000));

List my_list=ctr.my_list();

Criteria ctr=session.createCriteria.class("emp_record");

ctr.add(Restrictions(gt("salary>5000")));

List my_list= my_list(ctr);

Which of the following statements holds true for hibernate.jdbc.batch_size during Hibernate batching?

It controls the maximum number of statements that will be batched together by Hibernate, before asking the driver to execute the batch.

It names the implementation class and its size, used for managing the batch capabilities.

It forces the Hibernate to order inserts allowing more batching to be used.

It returns the row count when a batch is executed by Hibernate.

Hibernate 5.1.0 Skills Test Fiverr 2020

