Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "EclipseLink/Examples/JPARS/HelloDynamic"
< EclipseLink | Examples
(New page: == EclipseLink JPA-RS Example: Dynamic Hello World == This example illustrates the basic usage of EclipseLink's JPA-RS component combined with dynamic persistence to illustrate how JPA ca...) |
|||
Line 2: | Line 2: | ||
This example illustrates the basic usage of EclipseLink's JPA-RS component combined with dynamic persistence to illustrate how JPA can be exposed over REST without requiring any code on the server. This example documents the construction of the example application using Eclipse Juno's Java EE distribution. | This example illustrates the basic usage of EclipseLink's JPA-RS component combined with dynamic persistence to illustrate how JPA can be exposed over REST without requiring any code on the server. This example documents the construction of the example application using Eclipse Juno's Java EE distribution. | ||
− | |||
− | |||
== Steps == | == Steps == | ||
Line 16: | Line 14: | ||
## Add JPA-RS fragment to application | ## Add JPA-RS fragment to application | ||
## Configure persistence.xml | ## Configure persistence.xml | ||
+ | |||
+ | === Define Dynamic Entity === | ||
+ | |||
+ | <source lang="xml"> | ||
+ | <?xml version="1.0" encoding="UTF-8"?> | ||
+ | <entity-mappings version="2.4" xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/orm" | ||
+ | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
+ | xsi:schemaLocation="http://www.eclipse.org/eclipselink/xsds/persistence/orm http://www.eclipse.org/eclipselink/xsds/eclipselink_orm_2_4.xsd"> | ||
+ | |||
+ | <named-query name="Person.findLike"> | ||
+ | <query>SELECT p FROM Person p WHERE p.firstName LIKE :PATTERN OR p.lastName LIKE :PATTERN</query> | ||
+ | </named-query> | ||
+ | |||
+ | <entity class="model.Person" access="VIRTUAL"> | ||
+ | <attributes> | ||
+ | <id name="id" attribute-type="int" /> | ||
+ | <basic name="firstName" attribute-type="String"> | ||
+ | <column name="F_NAME" /> | ||
+ | </basic> | ||
+ | <basic name="lastName" attribute-type="String"> | ||
+ | <column name="L_NAME" /> | ||
+ | </basic> | ||
+ | </attributes> | ||
+ | </entity> | ||
+ | </entity-mappings> | ||
+ | </source> |
Latest revision as of 10:30, 10 August 2012
EclipseLink JPA-RS Example: Dynamic Hello World
This example illustrates the basic usage of EclipseLink's JPA-RS component combined with dynamic persistence to illustrate how JPA can be exposed over REST without requiring any code on the server. This example documents the construction of the example application using Eclipse Juno's Java EE distribution.
Steps
The basic steps for this constructing this demo from scratch are:
- Create a new Maven project
- Configure EclipseLink repository and dependency
- Enable and configure as dynamic web facet
- Configure EclipseLink
- Enable and configure JPA facet with EclipseLink library
- Add JPA-RS fragment to application
- Configure persistence.xml
Define Dynamic Entity
<?xml version="1.0" encoding="UTF-8"?> <entity-mappings version="2.4" xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eclipse.org/eclipselink/xsds/persistence/orm http://www.eclipse.org/eclipselink/xsds/eclipselink_orm_2_4.xsd"> <named-query name="Person.findLike"> <query>SELECT p FROM Person p WHERE p.firstName LIKE :PATTERN OR p.lastName LIKE :PATTERN</query> </named-query> <entity class="model.Person" access="VIRTUAL"> <attributes> <id name="id" attribute-type="int" /> <basic name="firstName" attribute-type="String"> <column name="F_NAME" /> </basic> <basic name="lastName" attribute-type="String"> <column name="L_NAME" /> </basic> </attributes> </entity> </entity-mappings>