Which of the following represents set of classes considered managed by MyPU?

Consider the following web application:

Here MyEntity1.class and MyEntity2.class are annotated with @Entity and MyEmbeddable1-class and MyEmbeddable2-class are annotated with @Embeddable. MyPU is container managed.
Which of the following represents set of classes considered managed by MyPU?

Consider the following web application:

Here MyEntity1.class and MyEntity2.class are annotated with @Entity and MyEmbeddable1-class and MyEmbeddable2-class are annotated with @Embeddable. MyPU is container managed.
Which of the following represents set of classes considered managed by MyPU?

A.
MyEntity1, and MyEmbeddable1

B.
MyEntity1, MyEmbeddable1, MyEntity2, and MyEmbeddable2

C.
MyEntity1, MyEmbeddable1, and MyEntity2

D.
MyEntity1 and MyEntity2



Leave a Reply 5

Your email address will not be published. Required fields are marked *


Albert Fröhlich

Albert Fröhlich

B
See JPA Specification
8.2.1.6 mapping-file, jar-file, class, exclude-unlisted-classes
The set of managed persistence classes that are managed by a persistence unit is defined by using one or more of the following:
– Annotated managed persistence classes contained in the root of the persistence unit (unless the exclude-unlisted-classes element is specified)
– One or more object/relational mapping XML files
– One or more jar files that will be searched for classes
– An explicit list of classes

test

test

B is the answer

Tommy_Croatia_ZGB

Tommy_Croatia_ZGB

Correct answer is B.

1. It is given that “MyPU” is container managed – This implies that all the classes contained in the Root of the PU will be inspected for meta data contained in annotations. (For a Java SE based PU, the specification requires that all the managed classes be listed in persistence.xml using elements.)

2. element is absent from the persistence.xml – This implies that all the classes need not be listed in the persistence.xml using elements. Classes can be implicity denoted as managed by putting them in appropriate locations.

3. Entity classes, embeddable classes, and mapped super classes must be explicitly or implicity denoted as managed classes. Here, “MyEntity1” and “MyEmbeddable1” are explicitly denoted as managed classes (because they are listed in persistence.xml), while “MyEntity2” and “MyEmbeddable2” classes are implicitly denoted as managed classes (because they are present in the root of the PU and are appropriately annotated with @Entity and @Embeddable). Therefore, it is clear that all four will be considered as managed by the PU.

Tommy_Croatia_ZGB

Tommy_Croatia_ZGB

I’m really annoyed by the fact that triangular brackets are not visible when you post an answer. I will repeat my answer and this time I will use curly brackets instead of triangular brackets.

1. It is given that “MyPU” is container managed – This implies that all the classes contained in the Root of the PU will be inspected for meta data contained in annotations. (For a Java SE based PU, the specification requires that all the managed classes be listed in persistence.xml using {class} elements.)

2. {exclude-unlisted-classes/} element is absent from the persistence.xml – This implies that all the classes need not be listed in the persistence.xml using {class} elements. Classes can be implicity denoted as managed by putting them in appropriate locations.

3. Entity classes, embeddable classes, and mapped super classes must be explicitly or implicity denoted as managed classes. Here, “MyEntity1” and “MyEmbeddable1” are explicitly denoted as managed classes (because they are listed in persistence.xml), while “MyEntity2” and “MyEmbeddable2” classes are implicitly denoted as managed classes (because they are present in the root of the PU and are appropriately annotated with @Entity and @Embeddable). Therefore, it is clear that all four will be considered as managed by the PU.