I have question how to store document that simple class as Order. The problem is my data "Item" as collection. Do i need some additional annotations in Item or Order ?
@Document(collection = "Order")
public class Order {
@Id
private String Id;
@Field(value="customer")
private String customer;
private String type;
private List<Item> items = new ArrayList<>() ;
public class Item {
private String id;
private Order order;
private String product;
private int price;
private int quantity;
Part of code when trying to save.
@Controller
@RequestMapping(value="/")
public class HomeController {
@Autowired
private OrderRepository repository;
@RequestMapping(method=RequestMethod.GET)
public String showHome(){
Item item1 = new Item("ItemOne", 88, 1);
Item item2 = new Item("Radio FLAC", 209, 1);
Order order = new Order("AAAAAAAA","local");
item1.setOrder(order);
item2.setOrder(order);
order.getItems().add(item1);
order.getItems().add(item2);
repository.insert(order);
// ArrayList<Order> orders;
//
// orders = (ArrayList<Order>) repository.findJankaOrders("");
//
// if(orders != null){
// for(Order order : orders){
// System.out.println(order);
// }
//
// }else
// System.out.println("there is nothing");
/* this query work as well */
System.out.println(repository.findAll());
return "home";
}
}
Error message is in loop and beginning at org.springframework.data.mapping.model.BasicPersistentEntity.getPropertyAccessor(BasicPersistentEntity.java:398):
java.lang.StackOverflowError
java.util.regex.Pattern$BmpCharProperty.match(Unknown Source)
java.util.regex.Pattern$Curly.match0(Unknown Source)
java.util.regex.Pattern$Curly.match(Unknown Source)
java.util.regex.Pattern$GroupHead.match(Unknown Source)
java.util.regex.Pattern$Branch.match(Unknown Source)
java.util.regex.Pattern$Branch.match(Unknown Source)
java.util.regex.Pattern$BmpCharProperty.match(Unknown Source)
java.util.regex.Pattern$Start.match(Unknown Source)
java.util.regex.Matcher.search(Unknown Source)
java.util.regex.Matcher.find(Unknown Source)
java.util.Formatter.parse(Unknown Source)
java.util.Formatter.format(Unknown Source)
java.util.Formatter.format(Unknown Source)
java.lang.String.format(Unknown Source)
org.springframework.data.mapping.model.BasicPersistentEntity.getPropertyAccessor(BasicPersistentEntity.java:398)
org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:406)
org.springframework.data.mongodb.core.convert.MappingMongoConverter.writePropertyInternal(MappingMongoConverter.java:519)
org.springframework.data.mongodb.core.convert.MappingMongoConverter$3.doWithPersistentProperty(MappingMongoConverter.java:430)
org.springframework.data.mongodb.core.convert.MappingMongoConverter$3.doWithPersistentProperty(MappingMongoConverter.java:418)
org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:312)
org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:418)
org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:392)
org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeCollectionInternal(MappingMongoConverter.java:630)
org.springframework.data.mongodb.core.convert.MappingMongoConverter.createCollection(MappingMongoConverter.java:554)
org.springframework.data.mongodb.core.convert.MappingMongoConverter.writePropertyInternal(MappingMongoConverter.java:465)
org.springframework.data.mongodb.core.convert.MappingMongoConverter$3.doWithPersistentProperty(MappingMongoConverter.java:430)
org.springframework.data.mongodb.core.convert.MappingMongoConverter$3.doWithPersistentProperty(MappingMongoConverter.java:418)