Oracle 1z0-898 Exam Practice Questions (P. 4)
- Full Access (63 questions)
- Six months of Premium Access
- Access to one million comments
- Seamless ChatGPT Integration
- Ability to download PDF files
- Anki Flashcard files for revision
- No Captcha & No AdSense
- Advanced Exam Configuration
Question #16
An application wants to utilize side effects of cascading entity manager operations to related entities.
Which statement is correct?
Which statement is correct?
- AThe persist operation is always cascaded to related entitles for one-to one and one-to-many relationships.
- BTo 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.
- CThe 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.
- DThe 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
Correct Answer:
C
The semantics of the flush operation, applied to an entity X are as follows:
* If X is a managed entity, it is synchronized to the database.
/ For all entities Y referenced by a relationship from X, if the relationship to Y has been annotated with the cascade element value cascade=PERSIST or cascade=ALL, the persist operation is applied to Y.
Reference:
http://stackoverflow.com/questions/4748426/cannot-remove-entity-which-is-target-of-onetoone-relation
(answer 1)
C
The semantics of the flush operation, applied to an entity X are as follows:
* If X is a managed entity, it is synchronized to the database.
/ For all entities Y referenced by a relationship from X, if the relationship to Y has been annotated with the cascade element value cascade=PERSIST or cascade=ALL, the persist operation is applied to Y.
Reference:
http://stackoverflow.com/questions/4748426/cannot-remove-entity-which-is-target-of-onetoone-relation
(answer 1)
send
light_mode
delete
Question #17
Given two entities with one to-one association:
@Entity public class Person {
@Id Integer id;
}
@Entity public class PersonDetail {
@Id Integer id;
}
Which code fragment correctly defines the detail field that PersonDetail instance in removed if the person instance that references it is removed?
@Entity public class Person {
@Id Integer id;
}
@Entity public class PersonDetail {
@Id Integer id;
}
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
Correct Answer:
C
Orphan Removal in Relationships -
When a target entity in one-to-one or one-to-many relationship is removed from the relationship, it is often desirable to cascade the remove operation to the target entity. Such target entities are considered "orphans," and the orphanRemoval attribute can be used to specify that orphaned entities should be removed. For example, if an order has many line items and one of them is removed from the order, the removed line item is considered an orphan. If orphanRemoval is set to true, the line item entity will be deleted when the line item is removed from the order.
The orphanRemoval attribute in @OneToMany and @oneToOne takes a Boolean value and is by default false.
The following example will cascade the remove operation to the orphaned customer entity when it is removed from the relationship:
@OneToMany(mappedBy="customer", orphanRemoval="true")
public List<Order> getOrders() { ... }
Reference: Orphan Removal in Relationships
C
Orphan Removal in Relationships -
When a target entity in one-to-one or one-to-many relationship is removed from the relationship, it is often desirable to cascade the remove operation to the target entity. Such target entities are considered "orphans," and the orphanRemoval attribute can be used to specify that orphaned entities should be removed. For example, if an order has many line items and one of them is removed from the order, the removed line item is considered an orphan. If orphanRemoval is set to true, the line item entity will be deleted when the line item is removed from the order.
The orphanRemoval attribute in @OneToMany and @oneToOne takes a Boolean value and is by default false.
The following example will cascade the remove operation to the orphaned customer entity when it is removed from the relationship:
@OneToMany(mappedBy="customer", orphanRemoval="true")
public List<Order> getOrders() { ... }
Reference: Orphan Removal in Relationships
send
light_mode
delete
Question #18
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 otherUsedNames 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@ElementCollection @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")
Correct Answer:
D
CollectionTable Specifies the table that is used for the mapping of collections of basic or embeddable types. Applied to the collection-valued field or property.
Example: @Entity public class WealthyPerson extends Person {
@ElementCollection
@CollectionTable(name="HOMES") // use default join column name
Reference: javax.persistence, Annotation Type CollectionTable
http://docs.oracle.com/javaee/6/api/javax/persistence/CollectionTable.html
Incorrect:
Not B: No such thing as @ElementTable in Java.
not C: SecondaryTable specifies a secondary table for the annotated entity class. Specifying one or more secondary tables indicates that the data for the entity class is stored across multiple tables.
D
CollectionTable Specifies the table that is used for the mapping of collections of basic or embeddable types. Applied to the collection-valued field or property.
Example: @Entity public class WealthyPerson extends Person {
@ElementCollection
@CollectionTable(name="HOMES") // use default join column name
Reference: javax.persistence, Annotation Type CollectionTable
http://docs.oracle.com/javaee/6/api/javax/persistence/CollectionTable.html
Incorrect:
Not B: No such thing as @ElementTable in Java.
not C: SecondaryTable specifies a secondary table for the annotated entity class. Specifying one or more secondary tables indicates that the data for the entity class is stored across multiple tables.
send
light_mode
delete
Question #19
Which statement is true about the @OrderColumn annotation?
- AIf mime is not specified, it defaults to the foreign key column.
- BThe OrderColumn annotation may be specified only on a relationship.
- CThe OrderColumn annotation is always specified on the owning side of a relationship.
- DThe order column is not visible as part of the state of the entity.
Correct Answer:
D
The order column is not visible as part of the state of the entity or embeddable class.
Reference: javax.persistence, Annotation Type OrderColumn
http://www.eclipse.org/eclipselink/api/2.0/javax/persistence/OrderColumn.html
D
The order column is not visible as part of the state of the entity or embeddable class.
Reference: javax.persistence, Annotation Type OrderColumn
http://www.eclipse.org/eclipselink/api/2.0/javax/persistence/OrderColumn.html
send
light_mode
delete
Question #20
Which cascade option can be specified in a mapping descriptor so that it applies to all relationships in a persistent e unit?
- Acascade all
- Bcascade detach
- Ccascade remove
- Dcascade-persist
Correct Answer:
D
cascade-persist
The cascade-persist subelement applies to all relationships in the persistence unit.
Specifying this subelement adds the cascade persist option to all relationships in addition to any settings specified in annotations or XML.
Reference: "Entity Classes from Database" needs CascadeType.PERSIST http://netbeans.org/bugzilla/show_bug.cgi?id=172098
D
cascade-persist
The cascade-persist subelement applies to all relationships in the persistence unit.
Specifying this subelement adds the cascade persist option to all relationships in addition to any settings specified in annotations or XML.
Reference: "Entity Classes from Database" needs CascadeType.PERSIST http://netbeans.org/bugzilla/show_bug.cgi?id=172098
send
light_mode
delete
All Pages