0

I am new to spring. I have

Customer.java

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OrderColumn;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import org.hibernate.annotations.Type;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;

import com.vividsolutions.jts.geom.Geometry;

@Entity
public class Customer
{
   @Id
   @GeneratedValue(strategy = GenerationType.IDENTITY)
   public long id;

   @Column(unique=true)
   @NotNull
   @Size(min = 1)
   public String username;

   static final int MAX_NAME_LENGTH = 255; 
   @Column(length=MAX_NAME_LENGTH)
   @Size(min = 1, max=MAX_NAME_LENGTH)
   @NotNull
   public String name;

   static final int MAX_EMAIL_LENGTH = 64; 
   @Column(length=MAX_EMAIL_LENGTH)
   @Size(min = 1, max=MAX_EMAIL_LENGTH)
   @NotNull
   public String email;

   static final int MAX_MOBILE_LENGTH = 16;
   @Column(length=MAX_MOBILE_LENGTH)
   @Size(min = 1, max=MAX_MOBILE_LENGTH)
   @NotNull
   public String mobile;

   static final int MAX_ADDRESS_LENGTH = 512;
   @Column(length=MAX_ADDRESS_LENGTH)
   @NotNull
   @Size(min = 1, max=MAX_ADDRESS_LENGTH)
   public String address;

   @Column(unique=true)
   @Type(type = "org.hibernate.spatial.GeometryType")
   public Geometry location;

   @OneToMany(targetEntity=OrderItem.class, fetch = FetchType.EAGER, cascade = CascadeType.ALL)
   @OrderColumn(nullable = false)
   public List<OrderItem> cart = new ArrayList<>();

   @OneToMany(mappedBy="customer")
   public List<Order> orders;

   public static interface Repository extends PagingAndSortingRepository<Customer, Long>
   {
      Customer findByUsername(@Param("username") String username);
   }
}

And my OrderItem.java

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

import org.springframework.data.repository.PagingAndSortingRepository;

@Entity
public class OrderItem
{
   @Id
   @GeneratedValue(strategy = GenerationType.IDENTITY)
   public long id;

   @ManyToOne
   @NotNull
   public Product product;

   @NotNull
   public int quantity;

   public static interface Repository extends PagingAndSortingRepository<OrderItem, Long>
   {
   }
}

When i run the hal-browser to

http://localhost:8080/api/v1/customers/1/cart Previously It was returning the

{
  "_links": {
    "self": {
      "href": "http://localhost:8080/api/v1/customers/1/cart"
    }
  },
  "_embedded": {
    "orderItems": [
      {
  ....}]}

But now after changing the version of spring to 4.2.0.RC3 and keeping jackson version as 2.6.1. _embedded is not coming in the json respose

its showing like

{
  "_links": {
    "self": {
      "href": "http://localhost:8080/api/v1/customers/1/cart"
    }
  }
}

Kindly advise.

useranon
  • 29,318
  • 31
  • 98
  • 146
  • Why are you using non final versions of the framework? Use `4.2.1.RELEASE` instead. Was that the only change or did you also upgrade Spring Data or other Boot dependencies? – M. Deinum Sep 08 '15 at 07:49
  • I tried using 4.2.1.RELEASE was getting many dependencies prblm. Finally with 4.2.0.RC3 application gets started. I kept jackson version as 2.6.1 form 2.5.3 and 0.19.0.RELEASE from 0.17.0.RELEASE – useranon Sep 08 '15 at 08:01
  • Please add other version updates to the question also I strongly recommend against using non final versions you are basically now using beta software in production... At least use the 4.2.0.RELEASE instead of the RC version. – M. Deinum Sep 08 '15 at 08:03
  • Tried with other latest versions as well. Its not coming. – useranon Sep 08 '15 at 12:28
  • You are using a lot of components, Spring Boot being one of them. Which versions are you using. Please add the information to your question, add a table with the frameworks and version changes. Hateoas might be one and that references have changed, the same for spring data rest. – M. Deinum Sep 08 '15 at 12:32

0 Answers0