Note that there are some explanatory texts on larger screens.

plurals
  1. PONot-null property references a transient value - transient instance must be saved before current operation
    text
    copied!<p>I have 2 domain models and one Spring REST Controller like below:</p> <pre><code>@Entity public class Customer{ @Id private Long id; @OneToOne(fetch = FetchType.EAGER) @JoinColumn(name="COUNTRY_ID", nullable=false) private Country country; // other stuff with getters/setters } @Entity public class Country{ @Id @Column(name="COUNTRY_ID") private Integer id; // other stuff with getters/setters } </code></pre> <p><strong>Spring REST Controller:</strong></p> <pre><code>@Controller @RequestMapping("/shop/services/customers") public class CustomerRESTController { /** * Create new customer */ @RequestMapping( method=RequestMethod.POST) @ResponseStatus(HttpStatus.CREATED) @ResponseBody public com.salesmanager.web.entity.customer.Customer createCustomer(@Valid @RequestBody Customer customer, Model model, HttpServletRequest request, HttpServletResponse response) throws Exception { customerService.saveOrUpdate(customer); return customer; } // other stuff } </code></pre> <p>I am trying to call above REST service with below JSON as body:</p> <pre><code>{ "firstname": "Tapas", "lastname": "Jena", "city": "Hyderabad", "country": "1" } </code></pre> <p>Where country code 1 is already there in Country table. The problem is when I am calling this service getting below error:</p> <pre><code>org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.TransientPropertyValueException: Not-null property references a transient value - transient instance must be saved before current operation: com.test.model.Customer.country -&gt; com.test.model.Country; nested exception is java.lang.IllegalStateException: org.hibernate.TransientPropertyValueException: Not-null property references a transient value - transient instance must be saved before current operation: com.test.model.Customer.country -&gt; com.test.model.Country </code></pre> <p>Any help will be appreciated!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload