Explore topic-wise InterviewSolutions in Current Affairs.

This section includes 7 InterviewSolutions, each offering curated multiple-choice questions to sharpen your Current Affairs knowledge and support exam preparation. Choose a topic below to get started.

1.

How You Can Make A Method Not Transactional If The Whole Class Was Marked As Transactional?

Answer»

using the ANNOTATION @NotTransactional above the method's NAME in the service

EXAMPLE:

IMPORT grails.transaction.Transactional

@Transactional
class BookService {
@NotTransactional
def listBooks() {
Book.list()
}
}

using the annotation @NotTransactional above the method's name in the service

Example:

import grails.transaction.Transactional

@Transactional
class BookService {
@NotTransactional
def listBooks() {
Book.list()
}
}

2.

How You Can Made A Method Of A Service Be Transactional?

Answer»

With the anotation @TRANSACTIONAL above the method's name of the SERVICE

EXAMPLE:

import grails.transaction.Transactional

class BookService {
@Transactional
DEF updateBook() {
// …
}
}

With the anotation @Transactional above the method's name of the service

Example:

import grails.transaction.Transactional

class BookService {
@Transactional
def updateBook() {
// …
}
}

3.

How Can You Made A All The Method Of A Service In Grails Be Transactional?

Answer»

with the anotation @TRANSACTIONAL above the CLASS's NAME

EXAMPLE:

IMPORT grails.transaction.*
@Transactional
class CountryService {
}

with the anotation @Transactional above the class's name

Example:

import grails.transaction.*
@Transactional
class CountryService {
}

4.

How Can You Install A Pluguin In Your Grails Application?

Answer»

you have to write your pluguin inside the pluguins Block/closure {} in the BuildConfig.groovy FILE and you have to specify if your pluguin works at RUN TIME or compilation time.

Example:

plugins {
BUILD ":tomcat:7.0.55"
compile ":scaffolding:2.1.2"
runtime ":jquery:1.11.1"
}

you have to write your pluguin inside the pluguins Block/closure {} in the BuildConfig.groovy file and you have to specify if your pluguin works at run time or compilation time.

Example:

plugins {
build ":tomcat:7.0.55"
compile ":scaffolding:2.1.2"
runtime ":jquery:1.11.1"
}

5.

What Is The Use Of Flush Option In Save Operation Of A Domain?

Answer»

SAVES the row immediately without any delay.

Example 

DEF BOOK = new Book(title:"New GRAILS Book")
book.save(flush:true)

Saves the row immediately without any delay.

Example 

def book = new Book(title:"New Grails Book")
book.save(flush:true)

6.

How You Can Create Many-to-many Relationship In Gorm?

Answer»

Many-to-many RELATIONSHIPS in Grails can be specified by DEFINING a hasMany property on both sides and having a belongsTo on the owned side:

CLASS TAG {
static belongsTo = Post
static hasMany = [POSTS: Post]
}
class Post {
static hasMany = [tags: Tag]
}

Many-to-many relationships in Grails can be specified by defining a hasMany property on both sides and having a belongsTo on the owned side:

class Tag {
static belongsTo = Post
static hasMany = [posts: Post]
}
class Post {
static hasMany = [tags: Tag]
}

7.

How You Can Create One-to-one Relationship In Gorm?

Answer»

There are two ways of specifying a one-to-one relationship:

FIRST Add an article PROPERTY and the unique constraint to the User domain:

class User {
Article article
STATIC CONSTRAINTS = {
article unique: TRUE
}
}
class Article {
static belongsTo = [user: User]
}

Second use the hasOne property on the owning (User) side:
class User {
static hasOne = [article: Article]
}
class Article {
static belongsTo = [user: User]
}

There are two ways of specifying a one-to-one relationship:

First Add an article property and the unique constraint to the User domain:

class User {
Article article
static constraints = {
article unique: true
}
}
class Article {
static belongsTo = [user: User]
}

Second use the hasOne property on the owning (User) side:
class User {
static hasOne = [article: Article]
}
class Article {
static belongsTo = [user: User]
}

8.

How You Can Create A Bidirectional Relationships In Gorm?

Answer»

using:

static belongsTo = USER

EXAMPLE:

CLASS User {
static hasMany = [ARTICLES: Article]
}
class Article {
static belongsTo = User
}

using:

static belongsTo = User

example:

class User {
static hasMany = [articles: Article]
}
class Article {
static belongsTo = User
}

9.

How You Can Create A One-to-many Relationship In Gorm?

Answer»

you can use STATIC hasMany property at the "ONE" SIDE

CLASS User {
static hasMany = [articles: ARTICLE]
}
 
class Article {
}

you can use static hasMany property at the "one" side: 

class User {
static hasMany = [articles: Article]
}
 
class Article {
}

10.

What Annotation Is Used For Unit Testing Of Grails Controller?

Answer»

grails.test.mixin.TestFor

grails.test.mixin.TestFor

11.

What Is New Scope Available In The Grails Services Which Makes Sure That A New Service Will Be Created For The Current And Next Request Only?

Answer»

Flash

Flash

12.

What Happens With The Db If You Have 'nothing/null' In The Option "dbcreate" Of Your Data Source?

Answer»

Does NOTHING with your DATA BASE

Does nothing with your data base

13.

What Happens With The Db If You Have 'validate' In The Option "dbcreate" Of Your Data Source?

Answer»

Makes no CHANGES to your database. Compares the CONFIGURATION with the existing database schema and reports WARNINGS.

Makes no changes to your database. Compares the configuration with the existing database schema and reports warnings.

14.

What Happens With The Db If You Have 'update' In The Option "dbcreate" Of Your Data Source?

Answer»

Creates missing TABLES and indexes, and updates the current schema without dropping any tables or data. Note that this can't properly handle many schema changes like column renames (you're LEFT with the OLD column containing the existing data).

Creates missing tables and indexes, and updates the current schema without dropping any tables or data. Note that this can't properly handle many schema changes like column renames (you're left with the old column containing the existing data).

15.

What Happens With The Db If You Have 'create-drop' In The Option "dbcreate" Of Your Data Source?

Answer»

Same as CREATE, but ALSO drops the TABLES when the application SHUTS down cleanly.

Same as create, but also drops the tables when the application shuts down cleanly.

16.

What Happens With The Db If You Have 'create' In The Option "dbcreate" Of Your Data Source?

Answer»

DROPS the existing schemaCreates the SCHEMA on startup, DROPPING existing TABLES, indexes, etc. first.

Drops the existing schemaCreates the schema on startup, dropping existing tables, indexes, etc. first.

17.

What Are The Differents Options To "dbcreate" Inside A Data Source Of An Environment?

Answer»

'CREATE', 'create-drop', 'update', 'validate' and ' NULL '

'create', 'create-drop', 'update', 'validate' and ' null '

18.

How You Can Use A Namespace Different Than "g: " To Render Your Tag Library In Your Views?

Answer»

USING the line in your TAG library:

static namespace = "your CUSTOM namespace"

using the line in your tag library:

static namespace = "your custom namespace"

19.

What Is The Command To Run Your App In A Custom Environment?

Answer»

GRAILS -Dgrails.env="your CUSTOM ENVIROMENT" run-app

grails -Dgrails.env="your custom enviroment" run-app

20.

How You Can Have Control Over The Way Grails Mapping The Urls In Your Application?

Answer»

In "conf/UrlMappings.groovy" you can CUSTOMIZE how GRAILS MAPS the URLS in your APPLICATION

In "conf/UrlMappings.groovy" you can customize how grails maps the URLs in your application

21.

How You Can Validate Your Domain Classes Against Invalid Data?

Answer»

USING : STATIC CONSTRAINTS{ }

using : static constraints{ }

22.

What Is Sitemesh?

Answer»

It's a HTML templating FRAMEWORK

It's a HTML templating framework

23.

How You Can Map Directly A Property Of A Domain Class To An Specific Column In Table Of Your Db?

Answer»

CLASS Person {
String firstName
STATIC MAPPING = {
table 'people'
firstName COLUMN: 'First_Name' ///this is the mapping of the columm in the table
}
}

class Person {
String firstName
static mapping = {
table 'people'
firstName column: 'First_Name' ///this is the mapping of the columm in the table
}
}

24.

How You Can Map Directly A Domain Class To An Specific Table In Your Db?

Answer»

in your DOMAIN CLASS:

class PERSON {

STATIC MAPPING = {
table 'people'///this is the mapping of the domain in the table
}
}

in your domain class:

class Person {

static mapping = {
table 'people'///this is the mapping of the domain in the table
}
}

25.

What Is The Difference Between User.findbyname() And User.findallbyname() In The Dynamic Finders?

Answer»

That Findbyname RETURN The FIRST RESULT And Findallbyname Return A LIST With All The RESULTS

That Findbyname Return The First Result And Findallbyname Return A List With All The Results

26.

What Is The Command To Compile Your Grails Application?

Answer»

GRAILS COMPILE

grails compile

27.

How You Can Use A Tag Library In Your View?

Answer»

<g:"your TAG library name" />

<g:"your tag library name" />

28.

What Is A Grails Pluguin?

Answer»

It's a bundle/set of FUNCTIONALITY to a desired PROPOSE that can be INSTALLED in your grails APPLICATION.

It's a bundle/set of functionality to a desired propose that can be installed in your grails application.

29.

What Is A Template In Grails?

Answer»

It's a REUSABLE PART of a VIEW that can be USED to RENDER a small part of a view.

It's a reusable part of a view that can be used to render a small part of a view.

30.

How Use Dynamic Scaffolding In Your App?

Answer»

in your CONTROLLER:

def SCAFFOLD=true or def scaffold="the NAME of your domain class"

in your controller:

def scaffold=true or def scaffold="the name of your domain class"

31.

How You Can Load Preload Data When Startup Your Aplication?

Answer»

USING Boostrap.groovy

using Boostrap.groovy

32.

How Render A Template In A View In Grails?

Answer»

USE the tag:
&LT;g:RENDER TEMPLATE="form"/&GT;

use the tag:
<g:render template="form"/>

33.

How Do You Inject A Service In Your Controller?

Answer»

DEF taskService

def taskService

34.

What Is Are The Closures In Groovy?

Answer»

A closure in Groovy is an open, ANONYMOUS, block of code that can take arguments, return a VALUE and be ASSIGNED to a variable.

A closure in Groovy is an open, anonymous, block of code that can take arguments, return a value and be assigned to a variable.

35.

What Is The Command To Create A Tag Library In Grails?

Answer»

GRAILS create-tag-library+ "packpage"+"NAME"

grails create-tag-library+ "packpage"+"name"

36.

What Is The Command To Create A Service In Grails?

Answer»

GRAILS create-SERVICE "packpage"+"service NAME"

grails create-service "packpage"+"service name"

37.

By Default Services In Grail Is Singleton Or Prototype?

Answer»

Singleton.

Singleton.

38.

What Option Do You Use To Create War File For Specific Environment?

Answer»

-Dgrails.env

EXAMPLE : GRAILS -Dgrails.env=dev WAR

-Dgrails.env

Example : grails -Dgrails.env=dev war

39.

What Is Command To Refresh Dependencies?

Answer»

GRAILS refresh-dependencies

grails refresh-dependencies

40.

What Is The Name Of Config File To Define Database Connection Properties?

Answer»

grails-app/conf/DataSource.groovy.

grails-app/conf/DataSource.groovy.

41.

What Is Javascript Tag In Gsp?

Answer»

INCLUDES JavaScript LIBRARIES and SCRIPTS as well as PROVIDING a shorthand for inline JavaScript.

Includes JavaScript libraries and scripts as well as providing a shorthand for inline JavaScript.

42.

How Do You Access Servlet Attributes From Controller?

Answer»

servletContext
servletContext is AVAILABLE in CONTROLLER.

servletContext
servletContext is available in controller.

43.

How Do You Render A Domain Object As Xml Or Json?

Answer»

RENDER Book.list(OBJECT) as JSON
render Book.get(object) as XML

render Book.list(object) as JSON
render Book.get(object) as XML

44.

How Can I Turn On Logging For Hibernate In Order To See Sql Statements, Input Parameters And Output Results?

Answer»

EDIT your Config.groovy file. FIND the line with:

HIBERNATE = "off"
and replace it with:
hibernate.SQL="trace,STDOUT"
hibernate.type="trace,stdout"

Edit your Config.groovy file. Find the line with:

hibernate = "off"
and replace it with:
hibernate.SQL="trace,stdout"
hibernate.type="trace,stdout"

45.

How Do You Secure Your Grails Application?

Answer»

USE GRAILS FILTER

Use Grails Filter

46.

What Is The Configuration File To Define Url Pattern And Its Controller And Action Name?

Answer»

grails-app/conf/UrlMappings.groovy.

grails-app/conf/UrlMappings.groovy.

47.

How Do You Configuring Eager Fetching In A Domain Class?

Answer»

using:

LAZY: FALSE
or
fetch: 'join'

Example:

CLASS AIRPORT {
String name
static hasMany = [flights: Flight]
static mapping = {
flights lazy: false //here you configure eager fetching
}
}

class Person {
String firstName
Pet pet
static hasMany = [addresses: Address]
static mapping = {
addresses lazy: false
pet fetch: 'join' //this is ANOTHER way to configure eager fetching
}
}

using:

lazy: false
or
fetch: 'join'

Example:

class Airport {
String name
static hasMany = [flights: Flight]
static mapping = {
flights lazy: false //here you configure eager fetching
}
}

class Person {
String firstName
Pet pet
static hasMany = [addresses: Address]
static mapping = {
addresses lazy: false
pet fetch: 'join' //this is another way to configure eager fetching
}
}

48.

Associations In Gorm Are By Default Lazy Or Eager?

Answer»

lazy

lazy

49.

What Is Dynamic Finders?

Answer»

Are the methods auto GENERATED by grails based on fields of the domain class.

Example. class Book {

String title
Date releaseDate
AUTHOR author
}

def book = Book.findByTitle("The STAND")
book = Book.findByTitleLike("Harry Pot%")

Are the methods auto generated by grails based on fields of the domain class.

Example. class Book {

String title
Date releaseDate
Author author
}

def book = Book.findByTitle("The Stand")
book = Book.findByTitleLike("Harry Pot%")

50.

What Method Do You Use To Check If Any Field Of An Object Has Been Modified?

Answer»

isDirty

getDirtyPropertyNames : to GET NAMES of MODIFIED FIELDS.

isDirty

getDirtyPropertyNames : to get names of modified fields.

Previous Next