0

我有疑问如何将简单类的文档存储为 Order。问题是我的数据“项目”作为集合。我需要在 Item 或 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;

尝试保存时的部分代码。

@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";

    }

}

错误消息在循环中并从 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)
4

0 回答 0