REST Test – Create JPA Entity

The REST services were based around a resource called AnEntity. The ‘AnEntity’ resources themselves were persisted using JPA.

Select New, Entity Class..., and then use Lombok to tidy up the code and add a simple attribute (called ‘name’) to give:

package com.nigeleke.restin.model;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.validation.constraints.NotNull;
import lombok.Data;

public @Data class AnEntity implements Serializable {

  public String toString() {
    return "com.nigeleke.restin.AnEntity[ id=" + id + ", name=" + name + "]";

  @GeneratedValue(strategy = GenerationType.AUTO)
  private Long id;

  private String name;

  private static final long serialVersionUID = 1L;

This step also create the persistence.xml file using restin as the JNDI name.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<persistence xmlns="" xmlns:xsi="" version="2.1" xsi:schemaLocation="">
  <persistence-unit name="restinPU" transaction-type="JTA">
      <property name="eclipselink.ddl-generation" value="create-tables"/>

Note, at this point, Netbeans enables you to set up a database referenced by the JNDI name. This will not be the database used during integration testing.

REST Test - Create Maven Web Application REST Test - Generate REST Service

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.