Java EE 6 Java Persistence API Developer Certified Expert Exam v8.0 (1z0-898)

Page:    1 / 3   
Total 36 questions

FooBean and BarBean are both EJB 3.0 stateless beans with container-managed transaction demarcation. All business methods in FooBean have transaction attribute
REQUIRED, and all business methods in BarBean have transaction attribute
REQUIRED_NEW. The business method foo in FooBean invokes the Business method bar in BarBean.
Given:
10. Public class BarBean {
11. public void bar () {
12. throw new RuntimeException (unexpected error . . . );
13. }}
Which is true about the method of invocation assuming execution reaches line 12?

  • A. FooBean.foo method receives javax.ejb.EJBException.
  • B. The BarBean bean instance is in ready state for the next invocation.
  • C. FooBean.foo method receives javax -ejb. EJBTtansactionRolledbackException.
  • D. FooBean.foo method receives the original RuntimeException thrown from BarBean.bar method.


Answer : A

Given two entities with many-to-many bidirectional association between them:


What set of annotations correctly defines the association?

  • A. @manyToMany on the projects field, @manyToMany (mappedBy= projects) on the emps field
  • B. @manyToMany (mappedBy = emps) on the projects field, @manyToMany on the emps field
  • C. @manyToMany ()targetEntity = project.class) on the projects field, @manyToMany (mappedBy = projects) on the emps field
  • D. @manyToMany (targetEntity = Project.class) on the projects field, @manyToMany on the emps field


Answer : C

Explanation: http://uaihebert.com/jpa-manytomany-unidirecional-e-bidirecional/

An application wants to utilize side effects of cascading entity manager operations to related entities.
Which statement is correct?

  • A. The persist operation is always cascaded to related entitles for one-to one and one-to- many relationships.
  • B. To minimize the effect of the remove operation applied to an entity participating in a many-to-many relationship the remove operation should he cascade to entities on both sides of the relationship.
  • C. The persist operation applied to a new entity x is cascaded to entities referenced by x if the relationship from x to these other entities is annotated with the cascade=PERSIST or cascade=ALL annotation element value.
  • D. The remove operation applied to a removed entity x is cascaded to entities referenced by x of the relationship from x to these other entities is annotated with the cascade = REMOVE of cascade = ALL annotation element value.


Answer : C

Reference:http://stackoverflow.com/questions/4748426/cannot-remove-entity-which-is- target-of-onetoone-relation(answer 1)

A developer wants to model the grades for a student as a Map<course, integer>. Assume that Student and Course are entitles, and that grades are modeled by integers.
Which of the following two statements are correct? (Choose two)

  • A. The developer can model the grades as an element collection in the Student entity.
  • B. The developer can model the grades as a oneToMany relationship in the Student entity.
  • C. The mapping for the key of the map can be specified by the @MapKeycolumn annotation.
  • D. The mapping for the value of the map can be specified by the @Column annotation.


Answer : A,D

Explanation: http://www.objectdb.com/api/java/jpa/MapKeyColumn

An entity person is mapped to a table PERSON and has a collection-valued persistence field otherUsedNames that stores names used by a person. The other used Names field is mapped to a separate table called NAMES. Which code fragment correctly defines such field?

  • A. @ElementCollection (name = NAMES) Protected set<String> otherUsedNames = new HashSet () ;
  • B. @Element collection @ElementTable (name = NAMES) Protected set<String> otherUsedNames = new HashSet () ;
  • C. @ElementCollection @SecondaryTable (names = NAMES) Protected set<String> otherUsedNames = new HashSet () ;
  • D. @ElementCollection @CollectionTable (names = Names) Protected set<String> otherUsedNames = new HashSet () ;


Answer : D

Reference:http://docs.oracle.com/javaee/6/api/javax/persistence/CollectionTable.html

A developer who is designing entity classes to map a legacy database encounters a table called STUDENT_RECORD.
This table has two columns, STUDENT_ID and STUDENT_INFO_ID. The primary key of this table consists of both columns, and there is a unique constraint on each info column.
The STUDENT_ID column is foreign key to the STUDENT table and STUDENT_INFO_ID column is a foreign key to the STUDENT_DAT table.
What entity classes and relationships can the developer use to model these tables and relationship?(Choose two)

  • A. Model the student table as a student entity and STUDENT_DATA table StudentData entity. Model the STUDENT_RECORDS table as bidirectional many-to-many relationship between the student entity on the student data entity.
  • B. Model the STUDENT table as a Student entity and the STUDENT-DATA table as a StudentData entity. Model the STUDENT_RECORD table as a bidirectional one-to-one relationship between the student entity and the StudentData entity.
  • C. Model the STUDENT table as a Student entity and the STUDENT-DATA table as a StudentData entity. Model the Student-Records table as a student record entity. Create a many-to-one one relationship from the StudentRecord entity to the student entity and many-to-one relationship from the StudentRecord entity entity to the Student entity and many-to-one relationship from the student entity to the StudentData entity and one-to-many relationship from the StudentData entity to the StudentRecord entity.
  • D. Model the STUDENT table as a Student entity and the STUDENT-DATA table as a StudentData entity. Model the STUDENT-RECORD table as a StudentRecord entity. Create a bidirectional one-to-one relationship between the StudentRecord entity and bidirectional one-to-one relationship between the Student Record entity and the Student Data entity.


Answer : A,C

Given:


Which statement is correct?

  • A. The method will return TRUE.
  • B. The method will return FALSE.
  • C. The method will throw an exception.
  • D. The order instance will be removed from the database.


Answer : C

Given two entities with one to-one association:


Which code fragment correctly defines the detail field that PersonDetail instance in removed if the person instance that references it is removed?

  • A. @OneToOne (optional = false) personDetail detail;
  • B. @OneToOne (optional = false) @mapsId PersonDetail Detail;
  • C. @ OneToOne (orphanremoval = true) PersonDetail Detail;
  • D. @ OneToOne (cascade = ORPHAN _ DELETE) @mapsId PersonDetail detail;


Answer : C

Given a set of CMT bean methods with the following transaction attributes:

Method M1 = SUPPORTS -

Method M2 = REQUIRED -

Method M3 = NOT_SUPPORTED -

Method M4 = REQUIRES_NEW -
And the following method invocation sequence:

Method M1 invokes Method M2 -

Method M2 invokes Method M3 -

Method M1 invokes Method M4 -
If Method M1 is invoked by a method that does NOT have a transaction context, which describes a possible scenario?

  • A. Method M1:notransaction MethodM2:newtransaction MethodM3:notransaction MethodM4:newtransaction
  • B. MethodM1:notransaction MethodM2:ContainerthrowsTransactionNotSupportedException
  • C. MethodM1:notransaction MethodM2:runsinsametransactionasM1 MethodM3:containerthrowsTransactionNotSupportException
  • D. MethodM1:notransaction MethodM2:newtransaction MethodM3:ContainerthrowsTransactionNotSupportException.


Answer : A

Explanation: http://docs.oracle.com/javaee/6/api/javax/ejb/TransactionAttributeType.html

QUESTIONNO:34 -
WhichEntityManagerAPIwilllockentityxwithapessimisticlock?
A.em.lock(x,LockModeType.WRITE)
B.em.lock(x,LockModeType.PESSIMISTIC)
C.em.lock(x,LockModeType.PESSIMISTIC_READ)
D.em.lock(x,LockModeType.OPTIMISTIC_FORCE_INCREMENT)

Answer:C -
Reference:http://www.objectdb.com/java/jpa/persistence/lock#Pessimistic_Locking_(pessi misticlocking)

QUESTIONNO:35 -
ItaPersistenceapplicationlocksentityxwithapessimisticlock,whichstatementistrue?
A.Persistenceprovidercandeferobtainingthelockuntilthenextsynchronizationofanentitytothed atabase
B.APersistenceproviderwillobtainthelockwhentheentityisrefreshedfromthedatabase
C.APersistenceproviderisnotrequiredtosupporttheLockModeType.PESSIMISTIC_WRITEloc kingtype
D.Ifalockcannotbeobtained,thePersistenceprovidermustthrowanexception

Answer:D -
Reference:http://www.eclipse.org/eclipselink/api/2.0/javax/persistence/LockModeType.html

Explanation -
:Whenthelockcannotbeobtained,andthedatabaselockingfailureresultsintransaction- levelrollback,theprovidermustthrowthePessimisticLockExceptionandensurethattheJTAtrans actionorEntityTransactionhasbeenmarkedforrollback.

QUESTIONNO:36 -
IfaPersistenceapplicationlocksentityxwithaLockModeType.OPTIMISTIC_FORCEINCREME
NTlocktype,whichstatementistrue?
A.ThePersistenceapplicationmustincrementtheversionvaluepriortolockingtheentity.
B.ThisoperationwillresultinaPersistentLockExceptionforanon-versionedobject.
C.ThisoperationwillresultinaPersistentLockExceptioniftheversionchecksfail.
D.LockModeType.OPTIMISTIC_FORCE_INCREMENTisthesynonymoftheLockModeType.
WRITElocktype.

Answer:D -
Reference:http://docs.oracle.com/javaee/6/tutorial/doc/gkjiu.html(seventhrowinthefirsttableo nthepage)

QUESTIONNO:37 -
PersistenceapplicationlocksentityxwithaLockModeType.PESSIMISTIC_READlocktype,whic hstatementistrue?
A.Thisoperationwillforceserializationamongtransactionsattemptingtoreadtheentitydata.
B.ThisoperationwillresultinaTransactionRolledbackExceptionifthelockcannotbeobtained.
C.Iftheapplicationlaterupdatestheentity,andthechangesareflushedtothedatabase,thelockwill beconvertedtoanexclusivelock.
D.LockModeType.PESSIMISTIC_READisthesynonymoftheLockModeType.READ.

Answer:C -

QUESTIONNO:38 -
Auserentityisretrievedinaqueryandstoredinaninstancevariableuser.Theuserentityhasasingle valuednamepropertythatusesthemappingdefaults,andaphotoproperty,whichislazilyloaded.T heapplicationthencallsthefollowingmethod:
PersistenceUtil.isLoaded(user);
Whichtwoofthefollowingstatementsarecorrect?
A.Thenamepropertywasloadedfromthedatabase.
B.ThenamepropertywasNOTbeloadedfromthedatabase.
C.Thenamepropertymayormaynothavebeenloadedfromthedatabase.
D.Thephotopropertywasloadedfromthedatabase.
E.ThephotopropertywasNOTloadedfromthedatabase.
F.Thephotopropertymayormaynothavebeenloadedfromthedatabase.

Answer:A,F -
Reference:http://docs.oracle.com/javaee/6/api/javax/persistence/PersistenceUtil.html http://stackoverflow.com/questions/10437552/what-does-persistenceutil-

Which cascade option can be specified in a mapping descriptor so that it applies to all relationships in a persistent e unit?

  • A. cascade all
  • B. cascade detach
  • C. cascade remove
  • D. cascade-persist


Answer : D

Reference:http://netbeans.org/bugzilla/show_bug.cgi?id=172098(second yellow box on the page)

An application that uses pessimistic locking calls an updateData method that results in a
LockTimeoutException being thrown. What three statements are correct? (Choose three)

  • A. The current transaction continues.
  • B. The current statement continues.
  • C. The current transaction is rolled back.
  • D. The current statement is rolled back.
  • E. The LockTimeoutException can NOT be caught.
  • F. The LockTimeoutException can be caught, and the updateData method retried.


Answer : A,D,F

If an application uses an extended persistence context, which of the following is true?

  • A. The persistence context exists until all transactions invoked by the EntityManager complete.
  • B. The persistence context exists until all transactions invoked by the EntityManagar complete and the EntityManager.clear () method is invoked.
  • C. The persistence context exists until the EntityManager instance is closed.
  • D. The persistence context exists until the EntityManagerFactory instance is closed.


Answer : C

Reference:http://java.boot.by/scbcd5-guide/ch07s03.html

The Contact Information embeddable class contains address information as well as a reference to a phone entity. The ContactInformation class is defined as follows:
@Embeddable public class ContactInformation {
String street;
String city;
@OneToOne Phone phone;
The developer wants to use this class in an Employee entity, but override the default name of the foreign key to the Phone entity. Which of the code segments shows how to do this correctly?

  • A. @Entity public class Employee { @Id int empId; @AssociationOverride (name = empInfo.phone, joinColumn = @JoinColumn) (name = INFO_FK)) ContactInformation empInfo; }
  • B. @AssociationOverride (name = empInfo.phone, joinColumn = INFO_FK) @Id int empId; @ContactInformation empInfo; }
  • C. @ AssociationOverride (name = empInfo.phone, joinColumn = INFO_FK) Entity public class Employee { @Id int empId; }
  • D. Entity public class Employee { @Id int empId; @ AssociationOverride (name = empInfo.phone, joinColumn = INFO_FK) ContactInformation empInfo; }


Answer : A

Reference:http://docs.oracle.com/javaee/6/api/javax/persistence/AssociationOverride.html

A developer has created an application managed entity manager.
Which statement is correct?

  • A. A new persistence context begins when the entity manager is created.
  • B. A new persistence context begins when a new JTA transaction begins.
  • C. A new persistence context begins when the entity manager is invoked in the context o\ transaction.
  • D. A new persistence context begins when the entity manager is invoked in the context of a resource-local transaction.


Answer : A

Reference:http://docs.oracle.com/javaee/6/tutorial/doc/bnbqw.html#bnbra

Which statement is true about the @OrderColumn annotation?

  • A. If mime is not specified, it defaults to the foreign key column.
  • B. The OrderColumn annotation may be specified only on a relationship.
  • C. The OrderColumn annotation is always specified on the owning side of a relationship.
  • D. The order column is not visible as part of the state of the entity.


Answer : D

Reference:http://www.eclipse.org/eclipselink/api/2.0/javax/persistence/OrderColumn.html(s econd paragraph)

Page:    1 / 3   
Total 36 questions