Use @NoSql
to specify a non-relational (that is, no SQL) data source. EclipseLink can map non-relational data to objects and access that data through JPA.
Table 2-42 describes this annotation's elements.
Table 2-42 @NoSql Annotation Elements
Annotation Element | Description | Default |
---|---|---|
|
The name of the entities structure. The purpose of the
|
|
|
(Optional) The type structure (data format) in which the data is stored within the database:
|
XML |
The dataFormat
depends on the NoSQL platform used:
For MongoDB, use MAPPED
.
For Oracle NoSQL, use MAPPED
(for key/value data) or XML
(for a single XML document).
For XML files and XML messaging, use XML
.
EclipseLink supports several NoSQL and EIS platforms, as well as generic NoSQL and EIS datasources through the JavaEE Connector Architecture CCI (Common Client Interface) API. You can also define your own EISPlatform
subclass and JCA adapter
EclipseLink supports the following datasources:
MongoDB
Oracle NoSQL
XML Files
JMS
Oracle AQ
Example 2-78 shows using @NoSql
with an XML data source.
Example 2-78 Using @NoSql Annotation with XML
@Entity @NoSql(dataType="order") public class Order { @Id @GeneratedValue @Field(name="@id") private long id; @Basic @Field(name="@description") private String description; @Embedded @Field(name="delivery-address") private Address deliveryAddress @ElementCollection @Field(name="orderLines/order-line") private List<OrderLine> orderLines; @ManyToOne @JoinField(name="customer-id") private Customer customer; } @Embeddable @NoSql public class OrderLine { @Field(name="@line-number") private int lineNumber; @Field(name="@item-name") private String itemName; @Field(name="@quantity") private int quantity; }
This would produce the following XML data:
<order id="4F99702B271B1948027FAF06" description="widget order"> <deliveryAddress street="1712 Hasting Street" city="Ottawa" province="ON" postalCode="L5J1H5"/> <order-lines> <order-line lineNumber="1" itemName="widget A" quantity="5"/> <order-line lineNumber="2" itemName="widget B" quantity="1"/> <order-line lineNumber="3" itemName="widget C" quantity="2"/> <order-lines> <customer-id>4F99702B271B1948027FAF08</customer-id> <order>
Example 2-79 shows using @NoSql
with a JSON data source.
Example 2-79 Using @NoSql Annotation with JSON
@Entity @NoSql(dataType="orders", dataFormat=DataFormatType.MAPPED) public class Order { @Id @GeneratedValue @Field(name="_id") private long id; @Basic @Field(name="description") private String description; @Embedded @Field(name="deliveryAddress") private Address deliveryAddress @ElementCollection @Field(name="orderLines") private List<OrderLine> orderLines; @ManyToOne @JoinField(name="customerId") private Customer customer; } @Embeddable @NoSql(dataFormat=DataFormatType.MAPPED) public class OrderLine { @Field(name="lineNumber") private int lineNumber; @Field(name="itemName") private String itemName; @Field(name="quantity") private int quantity; }
This would produce the following JSON document:
{ "_id": "4F99702B271B1948027FAF06", "description": "widget order", "deliveryAddress": { "street": "1712 Hasting Street", "city": "Ottawa", "province": "ON", "postalCode": "L5J1H5", }, "orderLines": [ {"lineNumber": "1", "itemName": "widget A", "quantity": "5"}, {"lineNumber": "2", "itemName": "widget B", "quantity": "1"}, {"lineNumber": "3", "itemName": "widget C", "quantity": "2"} ], "customerId": "4F99702B271B1948027FAF08", }
For more information, see:
Oracle Coherence Integration Guide for Oracle TopLink with Coherence Grid
"Using Non-SQL Databases" in Understanding Oracle TopLink
"Using NoSQL Databases" in Understanding Oracle TopLink
"Using TopLink with Nonrelational Databases" in Solutions Guide for Oracle TopLink