Professional Documents
Culture Documents
idname city t
Assumingthat necessaryimports are done.jdbctemplate is a valid reference of SpringjdbcTemplate, what is the output when
following code is executed?
String sql "update Customer set city? where city
System.out.printin (jdbcTemplate. update(sql,Texas "New York"))
w
ww
O wws
O N W
A
2
The
codewili throw PuntumeException
The code will throw RuntimeException.
Q2 of 15
Which of the following statement(s) is/are correct about methods of jdbcTemplate class?Choose any 2.
Q3 of 15
@Entity
Table(name="card")
public class CreditCard{
@Id
private Integer cardId;
private String cardNumber
private LocalDate expiryDate;
Ilgetter and set cer methods
iullaiililiui
ASsuming that necessary im orts are done, entityManager is a valid reference ofJPA EntityManager and transactions are managed by
Spring, what is the output when following code is executed?
card.setCardNumber(25666545
entityManager.persist(card)s w
entityManager.persist(card)
w
ww
W
T h e c o d e will throwttiatt
runtimewwwa
exception after inserting o n e row i n card
t
table
ifi
Ww
O n e row will be inserted in card table.
The code will throw runtime exception as unique constrant is violared. l Ass
Q4 of 15
Consider the following entity class:
@Entity
public class Customer{
@Id
1 Line 1
private Integer cust nerId;
private String name;
//getters and setters
www
www
ww
Which of the foliowing statement can be inserted at Line 1 to generate customerld using TABLE Strätegy?
ww
@Generatedvalue(strategy=GenerationType.TABLE)
@Generatevalue(strategy=GenerationType.TABLE)
@Generatedvaluestrategy="TABLE") E
@Generatedvaiuelstrategy=Generation.TABLE)
dAsessm
l Assessment- Persistence Layer using Spring ORM with Spring Boot
Q5 of 15
Consider the following table:
Assuming that springPhysir alNamingStrategy is followed, which of the following entity class is properly mapped to participant table?
Choose any 3.
@Entity public class Participant{ @ld private Integer participantid: @Columnname="name") private String
participantName; //getters and setters)
Q6 of 15
@Entity
public class Employee {
@Id
Assume that following seqi ance exists and no records existsin the table:
create sequence hibernate sequence start with 1 increment by 13
Assuming that necessary imports are done, entityManager is a valid reference ofJPA EntityManager and transactions are managed by
Spring. what is the output when following code is executed?
Employee employee =
new Employee()
Employee.setsalary(1000e);
entityManager.persist(employee)
System.out.println (employee.getEmployeeid ())
O2
null
02
O null
Q7 of 15
Which of the following anr tation you will for C
use
injecting EntityManager?
@PersistenceContext
O @PersistentContext
O@PersistContext
None of these
Q8 of 15
Consider the following tables and entity classes:
Transaction (transaction_id,
offer_price) where transaction_id is primary key.
Passenger(passenger_id. passenger_name, tid) where passenger_id is primary key and jd is foreign key referring to
transaction_id of Transaction table.
RE
@Entity
@Table(name ="Passenger") Ex
public class Passeng Entity {
@Id
private Inte er passengerId; Po
private String passengerName;
1/Line 1 Gro
private TransactionEntity transactionEntity;
//setter and getter methods
Orde
@Entity PQL
Table(name= "Transaction")
public class TransactionEntity { Update
@Id
@Column(name-"transaction_id") ; Quz:
private Integer transId;
private Double offerPrice;
Exercise-
//setter and getter methods
Apperd
www
Which of the following options when inserted at Line 1 brings one-to-one relationship between PassengerEntity and TransactionEntity
w
class?
@oneToOne(cascade=CascadeType.ALL)@joincolumn(name="trans id")
@OneToOnelcascade=CascadeType.ALL)@JoinColumntname="passenger_id", unique=true
Q9 of 15
Consider the following tatles and entity classes
Q9 of 15
Customer (custoner_id, custormer_name) where customer_id is primary key. to customer_id in the Customer table.
Transaction (transaction_jd, offer_price,.cust_id) where cust_id is foreign key referring
@Entity
public class Customer{
@Td
private Integer customerId;
private String custonerName;
1/Line 1
//setter and gettter ethods
@Entity
public class Transaction{
@Id
@Column(name "transaction_id")
private Integer transId;
private Double offerPrice;
//setter and getter methods
Which of the following option(s) can be inserted at Line 1 to bring one-to-many relationship between Customer and Transaction entity
classes?Choose any 2.
@Id wir
@column(name="transaction_id");
private Integer transId;
lillt
private Double offerPrice;
//setter and getter methods
il
Which of the follovwing option(s) can be inserted at Line 1 to bring one-to-many relationship between Customer and Transaction entity
:il
classes?Choose any2. 1
Q10 of 15
Consider the foilowing table and entity class:
@Entity
public class Instructor{
@Id
private Integer instructorId;
private 5tring instructorName;
private String skill;
/getter and setter
Assumingthat Instructor entity class is mapped with Instructor table and entityManager is a valid reference of JPA EntityManager
which of the following are correct optlon(s) to retrieve all instructors whose skili is "Java?
query.getResultlist();
OOnly 1. 2 and 4
Only 1 and 2
O n l y 1 and 4
O Only 2 and 4
Q11 of 15
e tat Customer entity ciass Is mapped to following customer table: lAss
Q11 of 15
customer table
Assume that Customer entity class is mapped to following
id namecity
=
1Tim Texas 43
2 Monica Plano 23
3Chris Washingtorn|28 transactions are managed by
Assuming that necessary imports a e done, entityManager is a valid reference of JPA EntityManager, and
Spring, what is the output when fo owing code is executed?
entityManager.c 2ateQuery (update customer c
set c.city ?1 where c.age?2);
Query query =
query.setParameter(1, "Plano")
query.setParameter (2,24);
List<Customer> result query.getResultList()
QEntity
@Table(name = "employee")
@Entity
@Table(name = "laptop")
Employee
@Entity
@Table(name "laptop")
public class LaptopEntity{
@Id
private Integer laptopId;
private String model;
1/getter and se ter
Employee
employee_idlemployee_namelaptop_id
3001 Tom 540
3002 Jack 541
Laptop
laptopid model
r
540 HP4120
541 Acer423
AssumingthatEmployee and Laptop tables are presentindatabase and mapped to Employee entity class and Laptop entity class.
entityManager is valid reference ofJPA EntityManager,and ransactions are managed by Spring. What is the output when following
code is executed?
O n erow of Employee table with employee_id=3001 is removed and no changes in Laptop table.
One row will be deleted from Employee table as well as Laptop table
one row of Laptop table withlaptop_id=540 is removed and no changes in Employee table
Q13 of 15
Q13 of 15
In Spring JDBC, to map each row of the table to an
object of model class which interface needs to be implemented?
RowMapper
MapRow
O oWMap
Mapper
Q14 of 15
Consider the following professor table with professor_id as primary key:
professor_id|department|
1001 Electronics
1002 Mechanical
1003
1004 Civil
1005 Mechanical
14 of 15
Consider the foliowing professor table with professor_id as primary key:
professor id department
|1001 Electronics
1002 |Mechanical
1003 EEE
1004 Civil
1005 Mechanical
1006 EEE
ASsuming that Professor e y class is mapped with professor table, entityManager is valid reference of JPA EntityManager, and
transactions are managed y Spring. what is the output when
following code is executed?
Query
queryentityManager.createQuery
-
query.setParameter ("EEE",1);
("UPDATE Professor p SET p.department 1 where p.professorId 22"):
query.setParameter (1881, 2)
int num= query.executeUpdate()
System.out.println (num) ;
O
professor d|ldepartment fntroduction
1001 Electronics
1002 |Mechanical Selection T
1003 EEE
Restriction -
=
|1004 Civil
|1005 |Mechanical
|1006 EEE
Exercise: JPQ=
Assuming that Professor entity class is mapped with professor table,
transactionsare
managed by Spring, what is the
entityManager is valid reference of JPA EntityManager, and PQL ARgregat-
output when following code is executed?
Query query entityMi 1ager.createQuery("UPDATE Professor p SET p.department = ?1 where p.professorId= ?2");
Grouping -The
query.setParameter("E",1);
query.setParameter(10 2); Ordering -The
int num=
query.execut ipdate();
System.out.println(nu
JPQL Functions
O Quiz:JPQL
O2 Exercise: JPQL
lAssessment Persistend
l Assessment Persistence Layer using
Spring
-
screen_idmovie_namerating|| Introc5
1001 Avengers 4.3
1002 Inception 4.5 SelectiF
1003 Deadpool 4
1004 Alien 3.9
Restric
1005 Deadpool4
Exercise
1006 Deadpool4
Assuming that Screen entity class is mapped with screen table, entityManager is
transactions are managed by Spring. What
valid reference ofJPA EntityManager, and PQL Ag
is the output when following code is executed?
Query updateQuery entityManager.createQuery("UPDATE Screen SET S.movieName ?1 where s.screenId
s Grouping
=
?2");
Query deleteQuery entityManager.createQuery("DELETE FROM Screen s where s.movieName = 'Deadpool ");
=
Quiz :JPQL
O3
Exercise : JPQI
4
Appendix
OTwo JPQL queries cannot perform operation on the same en
Assassmen -Persiste