Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

EclipseLink/Examples/PolyglotPersistence

< EclipseLink‎ | Examples
Revision as of 17:24, 3 April 2013 by Unnamed Poltroon (Talk) (New page: This example is a variation of the http://wiki.eclipse.org/EclipseLink/Examples/JPA/NoSQL NoSQL Example with some of the entities mapped to MongoDB and some to relational. The object...)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This example is a variation of the [NoSQL Example] with some of the entities mapped to MongoDB and some to relational. The object model and the configuration for MongoDB is described in that example and is not repeated here.

Domain Model

Two of the entities from the NoSQL example have been altered so that they are mapped to a relational database (MySQL in the this case). Those two entities are Discount and Product:

@Entity
public class Discount {
	@Id
	@GeneratedValue
	private int id;
	private float amount;
...
@Entity
public class Product {
	@Id
	@GeneratedValue
	private int id;
	private String description;
...

The Order and OrderLine, mapped to MongoDB, have relationships to Discount and Product, respectively.

@Entity
@NoSql(dataFormat=DataFormatType.MAPPED)
public class Order {   
    @Id // Use generated OID (UUID) from Mongo.
    @GeneratedValue
    @Field(name="_id")
    private String id;
    @Basic
    private String description;
    @OneToOne(cascade={CascadeType.REMOVE, CascadeType.PERSIST})
    private Discount discount;
 ...
@Embeddable
@NoSql(dataFormat=DataFormatType.MAPPED)
public class OrderLine implements Serializable {
    @Basic
    private int lineNumber;
    @OneToOne(cascade={CascadeType.REMOVE, CascadeType.PERSIST})
    private Product product;
...

Back to the top