250+ TOP MCQs on Hibernate and JPA Contextual Sessions and Answers

Java Spring MCQs on “Hibernate and JPA’s Contextual Sessions”.

1. Spring HibernateTemplate can simplify your DAO implementation by managing sessions and transactions for you.
a) True
b) False
Answer: a
Clarification: However, using HibernateTemplate means your DAO has to depend on Spring API.

2. An alternative to Spring HibernateTemplate is:-
a) HibernateContext
b) Hibernate contextual sessions
c) All of the mentioned
d) None of the mentioned
Answer: b
Clarification: An alternative to Spring HibernateTemplate is to use Hibernate contextual sessions.

3. Sessionfactory can manage contextual sessions for you and allows you to retrieve them by the:-
a) getSession() method
b) getCurrent() method
c) getCurrentSession() method
d) none of the mentioned
Answer: c
Clarification: In Hibernate 3, a sessionfactory can manage contextual sessions for you and allows you to retrieve them by the getCurrentSession() method on org.hibernate.SessionFactory.

4. DAO methods require access to the session factory, which can be injected:-
a) a setter method
b) constructor argument
c) none of the mentioned
d) all of the mentioned
Answer: d
Clarification: To use the contextual session approach, your DAO methods require access to the session factory, which can be injected via a setter method or a constructor argument.

5. DAO methods must be made transactional.
a) True
b) False
Answer: a
Clarification: This is required because Spring wraps the SessionFactory with a proxy that expects that Spring transaction management is in play when methods on a session are made.

6. Annotation to find a transaction and then fail, complaining that no Hibernate session been bound to the thread.
a) @Transaction
b) @Transactional
c) @Transactions
d) None of the mentioned
Answer: b
Clarification: This ensures that the persistence operations within a DAO method will be executed in the same transaction and hence by the same session.

7. In the bean configuration file for Hibernate (i.e., beans-hibernate.xml), you have to declare a HibernateTransactionManager instance for this application and enable declarative transaction via:-
a) tx:annotation
b) tx:annotationdriven
c) tx:annotation-driven
d) none of the mentioned
Answer: c
Clarification: In the bean configuration file for Hibernate (i.e., beans-hibernate.xml), you have to declare a HibernateTransactionManager instance for this application and enable declarative transaction management via tx:annotation-driven.

8. HibernateTemplate will translate the native Hibernate exceptions into exceptions in Spring DataAccessException hierarchy.
a) True
b) False
Answer: a
Clarification: This allows consistent exception handling for different data access strategies in Spring.

9. Annotation for Hibernate exceptions to be translated into Spring DataAccessException for consistent exception handling:-
a) @Translation
b) @Repo
c) @Repository
d) None of the mentioned
Answer: c
Clarification: If you want the Hibernate exceptions to be translated into Spring DataAccessException for consistent exception handling, you have to apply the @Repository annotation to your DAO class that requires exception translation.

10. Instance to translate the native Hibernate exceptions into data access exceptions in Spring DataAccessException hierarchy.
a) PersistenceExceptionPostProcessor
b) PersistenceExceptionTranslation
c) PersistenceException
d) PersistenceExceptionTranslationPostProcessor
Answer: d
Clarification: This bean post processor will only translate exceptions for beans annotated with @Repository.

11. You can assign a component name in this annotation and have the session factory autowired by the Spring IoC container with @Autowired.
a) True
b) False
Answer: a
Clarification: In Spring, @Repository is a stereotype annotation. By annotating it, a component class can be auto-detected through component scanning.

12. Spring provides to simplify your DAO implementation by managing entitymanagers and transactions for you:-
a) HibernateTemplate
b) JpaTemplate
c) SpringTemplate
d) None of the mentioned
Answer: b
Clarification: Using Spring JpaTemplate means your DAO is dependent on Spring API.

13. Annotation used for entity manager injection in EJB components.
a) @PersistenceContext
b) @Persistence
c) @PersistenceCon
d) None of the mentioned
Answer: a
Clarification: Spring can also interpret this annotation by means of a bean post processor.

14. To use the context injection approach, you can declare an entity manager field in your DAO and annotate it with the @PersistenceContext annotation.
a) True
b) False
Answer: a
Clarification: Spring will inject an entity manager into this field for you to persist your objects.

15. JpaTemplate will translate the native JPA exceptions into exceptions in Spring DataAccessException hierarchy.
a) True
b) False
Answer: a
Clarification: If you want JPA exceptions to be translated into Spring DataAccessException, you have to apply the @Repository annotation to your DAO class.

250+ TOP MCQs on Spring Batch infrastructure and Reading,Writing and Answers

Java Spring Multiple Choice Questions & Answers (MCQs) on “Spring Batch infrastructure and Reading, Writing”.

1. Spring Batch provides a lot of flexibility and guarantees to your application, but it cannot work in a vacuum. To do its work:-
a) Job
b) JobRepo
c) JobRepository
d) All of the mentioned
Answer: c
Clarification: To do its work, the JobRepository requires a database. Additionally, there are several collaborators required for Spring Batch to do its work. This configuration is mostly boilerplate.

2. There’s only one really useful implementation of the JobRepository interface, which stores information about the state of the batch processes in a database.
a) SimpleJobRepository
b) SimpleJob
c) SimpleRepo
d) All of the mentioned
Answer: a
Clarification: Creation is done through a JobRepositoryFactoryBean. Another standard factory, MapJobRepositoryFactoryBean is useful mainly for testing because its state is not durable – it’s an in-memory implementation. Both factories create an instance of SimpleJobRepository.

3. To load the contents of a properties file (batch.properties) whose values you use to configure the data source.
a) PropertyPlaceholder
b) PropertyPlaceholderConfigurer
c) Property
d) PropertyConfigurer
Answer: b
Clarification: You need to place values for your particular database in this file. This example uses Spring’s property schema (“p”) to abbreviate the tedious configuration.

4. MapJobRegistry instance. This is critical—it is the central store for information regarding a given Job.
a) True
b) False
Answer: a
Clarification: It controls the “big picture” about all Jobs in the system. Everything else works with this instance.

5. SimpleJobLauncher, whose sole purpose is to give you a mechanism to launch batch jobs, where a “job” in this case is our batch solution.
a) True
b) False
Answer: a
Clarification: The jobLauncher is used to specify the name of the batch solution to run as well as any parameters required.

6. Spring Batch models solutions using XML schema.
a) True
b) False
Answer: a
Clarification: This schema is new to Spring Batch 2.1.

7. However, it’s important to wear another hat, that of a DBA, when writing applications.
a) True
b) False
Answer: a
Clarification: A common solution is to create a denormalized table whose contents can be coerced into valid data once inside the database, perhaps by a trigger on inserts.

8. Indeed, a step could be considered the smallest unit of work for a job. Input (what’s read) is passed to the Step and potentially processed; then output (what’s written) is created from the step.
a) Steplet
b) Tasklet
c) All of the mentioned
d) None of the mentioned
Answer: b
Clarification: This processing is spelled out using a Tasklet. You can provide your own Tasklet implementation or simply use some of the preconfigured configurations for different processing scenarios.

9. Attribute to configure how many items will be processed before the transaction is committed all the input is sent to the writer.
a) interval
b) commit
c) commit-interval
d) none of the mentioned
Answer: c
Clarification: If there is a transaction manager in play, the transaction is also committed.

10. Class which delegates the task of delimiting fields and records within a file to a LineMapper, which in turn delegates the task of identifying the fields within that record, to LineTokenizer.
a) org.springframework.batch.item.file.FlatFileItemReader
b) org.springframework.batch.item.file.FlatFile
c) org.springframework.batch.item.file.FlatFileItem
d) org.springframework.batch.item.file.FileItemReader
View Answer

Answer: a
Clarification: The FlatFileItemReader also declares a fieldSetMapper attribute that requires an implementation of FieldSetMapper.

11. The names and values for the named parameters are being created by the bean configured for the itemSqlParameterSourceProvider property, an instance of the interface
a) BeanPropertyItemSqlParameterSourceProvider
b) BeanPropertyItemSqlParameterSource
c) BeanPropertyItemSqlParameter
d) All of the mentioned
Answer: a
Clarification: BeanPropertyItemSqlParameterSourceProvider, whose sole job it is to take JavaBean properties and make them available as named parameters corresponding to the property name on the JavaBean.

12. There’s support for writing JMS:-
a) JmsItemWriter
b) JpaItemWriter
c) JdbcBatchItemWriter
d) All of the mentioned
Answer: d
Clarification: There’s support for writing JMS (JmsItemWriter), JPA (JpaItemWriter), JDBC (JdbcBatchItemWriter), Files (FlatFileItemWriter), iBatis (IbatisBatchItemWriter), Hibernate (HibernateItemWriter), and more.

13. The processor attribute on the chunk element expects a reference to a bean of the interface:-
a) org.springframework.batch.item.Item
b) org.springframework.batch.item
c) org.springframework.batch.item.ItemProcessor
d) none of the mentioned
Answer: c
Clarification: The processor attribute on the chunk element expects a reference to a bean of the interface org.springframework.batch.item.ItemProcessor.

14. Spring Batch provides a convenience class, CompositeItemProcessor, which forwards the output of the filter to the input of the successive filter.
a) True
b) False
View Answer

Answer: a
Clarification: In this way, you can write many, singly focused ItemProcessors and then reuse them and chain them as necessary.

15. If the preceding job was run on a batch with a 100 rows, each item was read and passed through the processor, and it found 10 items invalid (it returned null 10 times), the value for the filter_count column would be:-
a) 100
b) 1
c) 10
d) 1000
Answer: c
Clarification: You could see that a 100 items were read from the read_count. The write_count column would reflect that 10 items didn’t make it and would show 90.

250+ TOP MCQs on Implementing and Injecting Beans with Scripting Languages and Answers

Java Spring Multiple Choice Questions & Answers (MCQs) on “Implementing and Injecting Beans with Scripting Languages”.

1. Scripting languages supported by Spring?
a) JRuby
b) Groovy
c) BeanShell
d) All of the mentioned
Answer: d
Clarification: Spring supports the 3 above mentioned scripting languages.

2. Scripting language based on Ruby
a) JRuby
b) Groovy
c) BeanShell
d) All of the mentioned
Answer: a
Clarification: JRuby is an open source Java-based implementation of the popular Ruby programming language.

3. Dynamic Language for java platform to cope up with other languages
a) JRuby
b) Groovy
c) BeanShell
d) All of the mentioned
Answer: b
Clarification: Groovy is a dynamic language for the Java platform that integrates the features of other excellent programming languages.

4. Lightweight java scripting language executing java fragments
a) JRuby
b) Groovy
c) BeanShell
d) All of the mentioned
Answer: c
Clarification: BeanShell is a lightweight Java scripting language that can dynamically execute Java code fragments while supporting scripting features like those of other scripting languages.

5. In Ruby instance variable begins with
a) #
b) *
c) @
d) None of the mentioned
Answer: c
Clarification: In Ruby, an instance variable begins with the @ sign.

6. XML Element to declare a bean implemented by JRuby
a) lang:jruby
b) aop:jruby
c) beanscript:jruby
d) script:jruby
Answer: a
Clarification: In the bean configuration file, you can declare a bean implemented with JRuby by using the lang:jruby.

7. XML element to specify the property values for scripting bean
a) lang:property
b) bean:property
c) script:property
d) None of the mentioned
Answer: a
Clarification: You can specify the property values for a scripting bean in the lang:property elements.

8. XML Element to declare a bean implemented by Groovy
a) lang:groovy
b) lang:jruby
c) beanscript:jruby
d) script:jruby
Answer: a
Clarification: In the bean configuration file, you can declare a bean implemented with Groovy by using the lang:groovy.

9. Script’s location is specified by attribute
a) script-source
b) xml-source
c) script-annotation
d) none of the mentioned
Answer: a
Clarification: Specifying the script’s location in the script-source attribute.

10. XML Element to declare a bean implemented by JRuby
a) lang:bash
b) aop:bash
c) lang:bsh
d) script:bash
Answer: c
Clarification: In the bean configuration file, you can declare a bean implemented with BeanShell by using the lang:bsh.

11. Interface used to create additional features in groovy based beans
a) GroovyObjectCustomizer
b) GroovyBeanCustomizer
c) GroovyCustomizer
d) None of the mentioned
Answer: a
Clarification: The GroovyObjectCustomizer interface is a callback that allows you to hook additional creation logic into the process of creating a Groovy-backed bean.

12. Attribute which specifies all the interfaces
a) script-interfaces
b) lang:bsh
c) lang:script
d) script:bsh
Answer: a
Clarification: Spring creates a JDK dynamic proxy implementing all of the interfaces that are specified in the ‘script-interfaces’.

13. Class-based proxies are best way to advise scripted beans
a) True
b) False
Answer: b
Clarification: There is just one (small) thing that you need to be aware of when advising scripted beans. You cannot use class-based proxies, you must use interface-based proxies.

14. Element which allows you to control the scope
a) lang:jruby
b) lang:language
c) lang: bsh
d) lang:groovy
Answer: b
Clarification: The scope attribute on the various lang:language/ elements allows you to control the scope of the underlying scripted bean, just as it does with a regular bean.

15. BeanShell Library dependencies
a) bsh-2.0b4.jar
b) cglib-nodep-2.1_3.jar
c) all of the mentioned
d) none of the mentioned
Answer: c
Clarification: All of these libraries are available in the Spring-with-dependencies distribution of Spring (in addition to also being freely available on the web).

250+ TOP MCQs on Spring BlazeDS support and Answers

Java Spring Interview Questions and Answers for experienced on “Spring BlazeDS support”.

1. The endpoint URL attribute defines where service is mounted.
a) endpoint URL
b) endpoint
c) endpoint service
d) none of the mentioned
Answer: a
Clarification: The endpoint URL attribute defines where we should expect this service to be mounted.

2. To keep our code as ready-to-deploy as possible.
a) parameterize the URL of the service in the client
b) add an entry to your /etc/hosts file on Unix derivatives or, on Windows, to your C:WINDOWSsystem32driversetchosts
c) none of the mentioned
d) all of the mentioned
Answer: d
Clarification: To keep our code as ready-to-deploy as possible, you should parameterize the URL of the service in the client. Alternatively, if you know the domain name for your application, you might add an entry to your /etc/hosts file on Unix derivatives or, on Windows, to your C:WINDOWSsystem32driversetchosts file mapping 127.0.0.1 to your target domain.

3. Spring BlazeDS creates existing Spring beans as AMF endpoints.
a) True
b) False
Answer: a
Clarification: Spring BlazeDS lets you expose existing Spring beans as AMF endpoints.

4. The service, which will simply fetch all the items that are for auction and return the description.
a) SpringBlaze DS
b) SpringFlex
c) EventSpring
d) All of the mentioned
Answer: a
Clarification: Use Spring BlazeDS to set up a simple service and demonstrate its invocation from the client—a simple auction application that we’ll build on in subsequent recipes.

5. To keep the code simpler.
a) Hibernate
b) Backing datastore
c) ConcurrentSkipListSet
d) None of the mentioned
Answer: c
Clarification: We’re not using Hibernate or any backing datastore to keep the code simpler. Instead, the service uses a ConcurrentSkipListSet instance variable.

6. Method which takes parameters required to describe a bid and creates it.
a) bid
b) acceptBid
c) all of the mentioned
d) none of the mentioned
Answer: a
Clarification: The bid method takes parameters required to describe a bid and creates it.

7. To notify other viewers of any new items posted.
a) javax.jms.Topic
b) jms
c) all of the mentioned
d) none of the mentioned
Answer: c
Clarification: We want to notify other viewers of any new items posted, we use JMS and a javax.jms.Topic.

8. Method, which is called after the component’s been configured by Spring
a) setupItems
b) setUp
c) setupFakeItems
d) all of the mentioned
Answer: c
Clarification: We spend some time constructing seed data in the setupFakeItems method, which is called after the component’s been configured by Spring.

9. To configure the standard Spring bean.
a) context:component-scan
b) context:scan
c) context:component
d) none of the mentioned
Answer: a
Clarification: There are two parts to the configuration: the standard services configuration, and the Spring BlazeDS configuration. We’ve already gone a long way to configuring the standard Spring beans with the addition of the context:component-scan element.

10. In Spring context XML for the message broker, we have.
a) flex
b) flex:message-broker
c) all of the mentioned
d) none of the mentioned
Answer: b
Clarification: Recall that in our Spring context XML for the message broker, we had a flex:message-broker element, in which we had a flex:message-service element.

11. flex:message-service element had an attribute.
a) default-channels
b) default-channel
c) default
d) default-types
Answer: a
Clarification: The flex:message-service element had an attribute, default-channels.

12. To use a different channel they’d like to use when communicating with the server.
a) flex:remoting-destination
b) flex:remote
c) flex:destination
d) flex:default-channels
Answer: a
Clarification: If, however, you’d like to use a different channel, then you may override it on the flex:remoting-destination element.

13. In ActionScript, “dynamic” means that you can arbitrarily add or reference fields only.
a) True
b) False
Answer: b
Clarification: In ActionScript, “dynamic” means that you can arbitrarily add or reference fields and methods on an object without type information.

14. ActionScript treats a class just like you could in the standard JavaScript.
a) True
b) False
Answer: a
Clarification: In the browser, this behavior is called expando properties and these are useful for us because Flash doesn’t have any built-in way of knowing (and surfacing to tools like your IDE’s auto-completion) the type information of the returned object.

15. Spring BlazeDS works with Spring Integration to let you bind any arbitrary endpoint.
a) True
b) False
Answer: a
Clarification: Spring BlazeDS works with Spring Integration to let you bind any arbitrary endpoint (be it an e-mail server, a Twitter user’s update feed, an FTP server, a file system, or anything for which you want to write an adapter) to the Spring BlazeDS messaging facilities.


Java Spring for interviews,

250+ TOP MCQs on Transaction Management and Answers

Java Spring Multiple Choice Questions & Answers (MCQs) on “Transaction Management”.

1. Transactions can be described with key properties:-
a) Atomicity
b) Consistency
c) Isolation
d) All of the mentioned
Answer: d
Clarification: The concept of transactions can be described with four key properties: atomicity, consistency, isolation, and durability (ACID).
• Atomicity: A transaction is an atomic operation that consists of a series of actions.
The atomicity of a transaction ensures that the actions either complete entirely or
take no effect at all.
• Consistency: Once all actions of a transaction have completed, the transaction is
committed. Then your data and resources will be in a consistent state that
conforms to business rules.
• Isolation: Because there may be many transactions processing with the same data
set at the same time, each transaction should be isolated from others to prevent
data corruption.
• Durability: Once a transaction has completed, its result should be durable to
survive any system failure (imagine if the power to your machine was cut right in
the middle of a transaction commit). Usually, the result of a transaction is
written to persistent storage.

2. To access a database running on the Derby server, you have to add:-
a) Derby client library
b) Tomcat client library
c) All of the mentioned
d) None of the mentioned
Answer: a
Clarification: To access a database running on the Derby server, you have to the Derby client library to your CLASSPATH.

3. Spring’s transaction support offers a set of technology-independent facilities, including transaction managers.
a) org.springframework.transaction.PlatformTransactionManager
b) org.springframework.transaction.support.TransactionTemplate
c) all of the mentioned
d) none of the mentioned
Answer: c
Clarification: Spring’s transaction support offers a set of technology-independent facilities, a transaction template (e.g., org.springframework.transaction.support.TransactionTemplate), and transaction declaration support to simplify your transaction management tasks.

4. Spring’s core transaction management abstraction is based on the interface:-
a) PlatformTransaction
b) PlatformTransactionManager
c) TransactionManager
d) PlatformManager
Answer: b
Clarification: It encapsulates a set of technology-independent methods for transaction management.

5. The PlatformTransactionManager interface provides methods for working with transactions:
a) getTransaction(TransactionDefinition definition)
b) commit(TransactionStatus status)
c) rollback(TransactionStatus status)
d) all of the mentioned
Answer: d
Clarification:
• TransactionStatus getTransaction(TransactionDefinition definition) throws
TransactionException
• void commit(TransactionStatus status) throws TransactionException;
• void rollback(TransactionStatus status) throws TransactionException;

6. Spring has several built-in implementations of PlatformTransactionManager interface for use with different transaction management APIs.
a) True
b) False
Answer: a
Clarification:
• If you have to deal with only a single data source in your application and access it
with JDBC, DataSourceTransactionManager should meet your needs.
• If you are using JTA for transaction management on a Java EE application server,
you should use JtaTransactionManager to look up a transaction from the
application server. Additionally, JtaTransactionManager is appropriate for
distributed transactions (transactions that span multiple resources). Note that
while it’s common to use a JTA transaction manager to integrate the application
servers’ transaction manager, there’s nothing stopping you from using a stand-
alone JTA transaction manager such as Atomikos.
• If you are using an object/relational mapping framework to access a database, you
should choose a corresponding transaction manager for this framework, such as
HibernateTransactionManager and JpaTransactionManager.

7. A transaction manager is declared in the Spring IoC container as a normal bean.
a) True
b) False
Answer: a
Clarification: For example, the following bean configuration declares a DataSourceTransactionManager instance. It requires the dataSource property to be set so that it can manage transactions for connections made by this data source.

8. Method that allows you to start a new transaction (or obtain the currently active transaction).
a) getTransaction()
b) commit()
c) rollback()
d) all of the mentioned
Answer: a
Clarification: Spring’s transaction manager provides a technology-independent API that allows you to start a new transaction (or obtain the currently active transaction) by calling the getTransaction() method.

9. PlatformTransactionManager is an abstract unit for transaction management.
a) True
b) False
Answer: a
Clarification: Because PlatformTransactionManager is an abstract unit for transaction management, the methods you called for transaction management are guaranteed to be technology independent.

10. Method to start a new transaction with that definition:-
a) getTransaction()
b) commit()
c) rollback()
d) none of the mentioned
Answer: a
Clarification: Once you have a transaction definition, you can ask the transaction manager to start a new transaction with that definition by calling the getTransaction() method.

11. To help you control the overall transaction management process and transaction exception handling.
a) SpringTransactionTemplate
b) TransactionTemplate
c) Transaction
d) None of the mentioned
Answer: b
Clarification: Spring also provides a TransactionTemplate to help you control the overall transaction management process and transaction exception handling.

12. You just have to encapsulate your code block in a callback class that implements the TransactionCallback interface and pass it to the TransactionTemplate execute method for execution. In this way, you don’t need to repeat the boilerplate transaction management code for this block.
a) True
b) False
View Answer

Answer: a
Clarification: In this way, you don’t need to repeat the boilerplate transaction management code for this block.

13. A TransactionTemplate can accept a transaction callback object that implements:-
a) TransactionCallback
b) TransactionCallbackWithoutResult class
c) All of the mentioned
d) None of the mentioned
Answer: c
Clarification: A TransactionTemplate can accept a transaction callback object that implements either the TransactionCallback or an instance of the one implementer of that interface provided by the framework, the TransactionCallbackWithoutResult class.

14. Spring (since version 2.0) offers a transaction advice that can be easily configured via the:-
a) rx:advice
b) bx:advice
c) tx:advice
d) none of the mentioned
Answer: c
Clarification: This advice can be enabled with the AOP configuration facilities defined in the aop saop schema.

15. You can omit the transaction-manager attribute in the element if your transaction manager has the name transactionManager.
a) True
b) False
View Answer

Answer: a
Clarification: This element will automatically detect a transaction manager with this name. You have to specify a transaction manager only when it has a different name.


250+ TOP MCQs on Transactions and Retrying and Answers

Java Spring Questions & Answers for entrance exams on “Transactions and Retrying”.

1. Transaction capabilities are built on top of the first class support already provided by the core Spring framework.
a) True
b) False
Answer: a
Clarification: Where relevant, Spring Batch surfaces the configuration so that you can control it.

2. Spring core framework provides first-class support for transactions.
a) Transaction
b) TransactionManager
c) All of the mentioned
d) None of the mentioned
Answer: b
Clarification: You simply wire up a TransactionManager and give Spring Batch a reference, just as you would in any regular JdbcTemplate or HibernateTemplate solution.

3. The batch.xml file establishes a:-
a) BasicDataSource
b) DataSourceTransactionManager
c) All of the mentioned
d) None of the mentioned
Answer: c
Clarification: The TransactionManager and BasicDataSource were then wired to the JobRepository, which was in turn wired to the JobLauncher, which you used to launch all jobs thus far.

4. Spring Batch will, by default, try to pluck the:-
a) PlatformTransactionManager
b) transactionManager
c) All of the mentioned
d) None of the mentioned
Answer: c
Clarification: The transaction manager reference can be specified, but in your solutions, it wasn’t required because Spring Batch will, by default, try to pluck the PlatformTransactionManager named transactionManager from the context and use it.

5. Spring Batch excels in the robustness it surfaces as simple configuration options for the edge and failure cases.
a) True
b) False
Answer: a
Clarification: If a write fails on an ItemWriter, or some other exception occurs in processing, Spring Batch will rollback the transaction.

6. Element to configure this for the step:-
a) no-rollback-exception-classes
b) no-rollback-exception
c) no-rollback
d) none of the mentioned
Answer: a
Clarification: You can use the no-rollback-exception-classes element to configure this for the step. The value is a list of Exception classes that should not cause the transaction to roll back.

7. no-rollback-exception-classes element Exception classes that should not cause the transaction to roll back.

<step id = "step2">
   <tasklet>
           <chunk reader="reader" writer="writer" commit-interval="10" />
           <no-rollback-exception-classes>
           <include class="com.yourdomain.exceptions.YourBusinessException"/>
           no-rollback-exception-classes>
   tasklet>
step>

a) True
b) False
Answer: a
Clarification: You can use the no-rollback-exception-classes element to configure this for the step. The value is a list of Exception classes that should not cause the transaction to roll back.

8. You want to work with a resource that may fail when you try to read from or write to it.
a) TransactionManager
b) Transaction
c) Spring batch retry
d) All of the mentioned
Answer: c
Clarification: Use Spring Batch retry capabilities to systematically retry the read or write.

9. Some invocations will fail but may be retried with some likelihood of success in a transactional scenario.
a) True
b) False
Answer: b
Clarification: For example, an update to the database resulting in org.springframework.dao.DeadlockLoserDataAccessException might be usefully retried.

10. You can specify exception classes on which to retry the operation.

<step id = "step23">
       <tasklet transaction-manager="transactionManager">
            <chunk reader="csvFileReader" writer="jdbcItemWriter" commit-interval="10" retry-limit="3" cache-capacity="10">
           <retryable-exception-classes>
           <include class="org.springframework.dao.DeadlockLoserDataAccessException"/>
           retryable-exception-classes> 
           chunk>
       tasklet>
step>

a) True
b) False
Answer: a
Clarification: As with the rollback exceptions, you can delimit this list of exceptions with newlines or commas.

11. You can leverage Spring Batch support for retries and recovery in your own code.
a) True
b) False
Answer: a
Clarification: For example, you can have a custom ItemWriter in which retry functionality is desired or even an entire service interface for which retry support is desired.

12. The template that (much like its various other Template cousins) isolates your logic from the nuances of retries and instead enables you to write the code as though you were only going to attempt it once.
a) Retry
b) RetryTemplate
c) All of the mentioned
d) None of the mentioned
Answer: b
Clarification: Spring Batch supports these scenarios through the RetryTemplate that (much like its various other Template cousins) isolates your logic from the nuances of retries and instead enables you to write the code as though you were only going to attempt it once.

13. The RetryTemplate supports many use cases, with convenient APIs to wrap.
a) True
b) false
Answer: a
Clarification: Otherwise tedious retry/fail/recover cycles in concise, single-method invocations.

14. The RetryTemplate itself is configured in the Spring context, although it’s trivial to create in code.
a) True
b) False
Answer: a
Clarification: I declare it in the Spring context only because there is some surface area for configuration when creating the object, and I try to let Spring handle the configuration.

15. One of the more useful settings for the RetryTemplate is the :-
a) BackOff
b) Back
c) BackOffPolicy
d) All of the mentioned
Answer: c
Clarification: BackOffPolicy dictates how long the RetryTemplate should back off between retries.


To practice all areas of Java Spring for entrance exams,