mercredi 1 juillet 2015

Is the JPA @Embedded annotation mandatory?

I have tried omitting the @Embedded annotation and still the fields have been embedded in the table. I cannot find anything which would say that the @Embedded annotation is optional.

Is it or is it not optional?

The following code

@Embeddable
public class Address {
    String city;
    String street;
}

@Entity
public class Person {
    String name;
    @Embedded // it seems that it works even if this annotation is missing!?
    Address address;
}

generates always the same table

person
    name
    city
    street

even if I do not specify @Embedded.


My configuration:

  • JBoss EAP 6.4.0
  • hibernate-jpa-2.0-api-1.0.1.Final-redhat-3.jar

The JPA specification says:

http://ift.tt/1GYDTyY

@javax.persistence.Embedded

Specifies a persistent field or property of an entity whose value is an instance of an embeddable class. The embeddable class must be annotated as Embeddable.

http://ift.tt/1GYDTz0

@javax.persistence.Embeddable

Specifies a class whose instances are stored as an intrinsic part of an owning entity and share the identity of the entity. Each of the persistent properties or fields of the embedded object is mapped to the database table for the entity.

Aucun commentaire:

Enregistrer un commentaire