I am trying to send two data to my RESTful server running on glassfish. The user has to select a restaurant in the datalist. I want to send an id and a name of the restaurant. With console.log I can print out the values of the id and name, but my response returns null. Any idea why this happens and how to solve it?

ts file

```
export class OrganizeComponent implements OnInit {

  public codeValue: string;

  codeList = [
    { id: 1, name: 'Mcdonalds' },
    { id: 2, name: 'Kentucky Fried Chicken' },
    { id: 3, name: 'Burger King' },
    { id: 4, name: 'Domino`s pizza' },
    { id: 5, name: 'New York Pizza' }
  ];

  @ViewChild('f') form: NgForm;
  restaurant = {
    id: 0,
    name: ''
  };

  constructor(private http: HttpClient) {
  }

  ngOnInit() {
  }

  public saveCode(e): void {
    let name = e.target.value;
    let list = this.codeList.filter(x => x.name === name)[0];
    // console.log(list.id);
    // console.log(list.name)

    this.restaurant.id =  list.id;
    this.restaurant.name = list.name;

console.log(list.id);
console.log(list.name);

    this.http.post('http://localhost:8080/aquadine-jee/resources/restaurant', {
      id: list.id,
      name: list.name
    })

      .subscribe( // subscribe to observable http.post
        res => {
          console.log("response" + " " + res); // log results otherwise log error
        },
        err => {
          console.log('Error occured');
        }
      );

```

Html file

```
<label for="codes">Choose a restaurant:</label>
    <form
      (ngSubmit)="onOrganize(f)"
      #f="ngForm">
      <input type="text"  list="codes"  [(ngModel)]=codeValue [ngModelOptions]="{standalone: true}" (change)="saveCode($event)">
      <datalist id="codes">
        <option *ngFor="let c of codeList" [value]="c.name" >{{c.name}}</option>
      </datalist>
    </form>

```

Backend code:

```
@Stateless
@Path("restaurant")
public class RestaurantResource {

    @Inject
    private RepositoryService repositoryService;

    @GET
    @Path("restaurant")
    @Produces("application/json")
    public Response all(){
        List<Restaurant> all = repositoryService.getAllRestaurants();
        return Response
                .status(200)
                .header("Access-Control-Allow-Origin", "*")
                .entity(all)
                .build();
    }

    @GET
    @Produces("application/json")
    public List<Restaurant> getAllRestaurants(){
        return repositoryService.getAllRestaurants();

    }

    @POST
    @Consumes("application/json")
    public Response save(Restaurant restaurant){
        repositoryService.save(restaurant);
        return Response
                .status(201)
                .build();
    }

```

```
public class Restaurant {

    @Id
    @Column(name="idRestaurant")
    @NotBlank
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    public Restaurant(Integer id,Integer restaurantId , String naam) {
        this.id = id;
        this.restaurantId = restaurantId;
        this.naam = naam;
    }

```

Error in backend service:

> 
> internal server error 500. A system exception occurred during an
>  invocation on EJB RepositoryService, method: public void
>  nl.aquadine.service.RepositoryService.save(nl.aquadine.model.Restaurant)]]
>  and javax.ejb.TransactionRolledbackLocalException: Exception thrown
>  from bean and Caused by: org.hibernate.PersistentObjectException:
>  detached entity passed to persist: nl.aquadine.model.Restaurant at
>  org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:124)
>  at org.hibernate.event.internal.DefaultPersis etc.
> 
> 
>