ObjectDB ObjectDB

Cascade type annotaion on an embeddable type

#1

Assume we have the following classes:


@Entity
public class Restaurant
{
    /* @Embedded */ private Location location;
    private int phoneNumber;
}


@Embeddable
public class Location
{
    private double latitude;
    private double longitude;
}

According to the documentation, the @Embedded annotation "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."

So the Location class is annotated as instructed, but what difference will it make if we would annotate the Location field with the @Embedded annotation? And do we have to use this annotation also?

In addition, does CascadeType affects embeddable objects?

edit
delete
#2

No need to specify the Embedded annotation in this case. You may specify it if you think that it may improve the clarity of your code (as it will be clear that location is embedded and not a separate entity when looking at the Restaurant class with no need to look at Location).

Embedded objects are part of the containing entity objects. Because they are not separate entity objects and not stored in the database in a separate location cascading is not required for the embedded objects themselves.

There could be some specific case in which specifying Embedded is needed and it is related to cascading. If the embedded object contains a reference to an entity object with cascading annotation, it will be ignored by ObjectDB (this could be changed in the future) unless you annotate that embedded object explicitly as Embedded.

ObjectDB Support
edit
delete
#3

Thanks for the clarification.smiley

edit
delete

Reply

To post on this website please sign in.