title: How to store java objects in mysql using jpa?
body: <p>I have converted the JSON into POJO using GSON.
  I am looking to store Employee entity object into mysql using JPA's save() method. But I am getting an error saying "cannot determine the type for Address". So how should I go with this?</p>
  
  <p>Here is the error:
  Could not determine type for : Address</p>
  
  <p>Employee.java</p>
  
  <pre><code>package com.example.demo;
  
  import java.math.BigDecimal;
  import java.util.Map;
  
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.Id;
  
  import com.google.gson.annotations.Expose;
  
  @Entity
  public class Employee {
  
  @Id
  private int id;
  private String name;
  private int age;
  private BigDecimal salary;
  private String designation;
  private Address address;
  private long[] phoneNumbers;
  
  /*Getter and Setter Methods*/
  public int getId() {
      return id;
  }
  
  public void setId(int id) {
      this.id = id;
  }
  
  public String getName() {
      return name;
  }
  
  public void setName(String name) {
      this.name = name;
  }
  
  public int getAge() {
      return age;
  }
  
  public void setAge(int age) {
      this.age = age;
  }
  
  public BigDecimal getSalary() {
      return salary;
  }
  
  public void setSalary(BigDecimal salary) {
      this.salary = salary;
  }
  
  public String getDesignation() {
      return designation;
  }
  
  public void setDesignation(String designation) {
      this.designation = designation;
  }
  
  
  public long[] getPhoneNumbers() {
      return phoneNumbers;
  }
  
  public void setPhoneNumbers(long[] phoneNumbers) {
      this.phoneNumbers = phoneNumbers;
  }
  
  public Address getAddress() {
      return address;
  }
  
  public void setAddress(Address address) {
      this.address = address;
  }
  
  
  }
  </code></pre>
  
  <p>Address.java</p>
  
  <pre><code>package com.example.demo;
  
  import javax.persistence.Entity;
  import javax.persistence.Id;
  
  //@Entity
  public class Address {
  @Id
  private String street;
  private String city;
  private int zipCode;
  public String getStreet() {
      return street;
  }
  public void setStreet(String street) {
      this.street = street;
  }
  public String getCity() {
      return city;
  }
  public void setCity(String city) {
      this.city = city;
  }
  public int getZipCode() {
      return zipCode;
  }
  public void setZipcode(int zipcode) {
      this.zipCode = zipcode;
  }
  @Override
  public String toString(){
      return getStreet() + ", "+getCity()+", "+getZipCode();
  }
  }
  </code></pre>
  
  <p>Controller Class</p>
  
  <pre><code>package com.example.demo;
  
  import net.sf.json.*;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Controller;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.GetMapping;
  import org.springframework.web.bind.annotation.RequestBody;
  import org.springframework.web.bind.annotation.ResponseBody;
  
  import com.google.gson.Gson;
  import com.google.gson.GsonBuilder;
  import com.google.gson.JsonObject;
  
  import net.sf.json.JSONObject;
  
  @Controller    // This means that this class is a Controller
  @RequestMapping(path="/demo") // This means URL's start with /demo 
  (after Application path)
  public class MainController {
  @Autowired // This means to get the bean called userRepository
             // Which is auto-generated by Spring, we will use it 
  to handle the data
  private UserRepository userRepository;
  
  @GetMapping(path="/add") // Map ONLY GET Requests
  public @ResponseBody String addNewUser (@RequestBody String json) { 
      // @ResponseBody means the returned String is the response, not a view name
      // @RequestParam means it is a parameter from the GET or POST request
  
  
      //JSONObject jsonObject = JSONObject.fromObject(json);
      Gson gson=new GsonBuilder().create();
      Employee employee =gson.fromJson(json,Employee.class);
      userRepository.save(employee);
      return "Successfully added to database using JPA!";
      }
  
  @GetMapping(path="/all")
  public @ResponseBody Iterable&lt;Employee&gt; getAllUsers() {
      // This returns a JSON or XML with the users
      return userRepository.findAll();
  }
  }
  </code></pre>