मैं मॉडलस्प्रिंग MongoDB टेम्पलेट एक ही वस्तु में बचत होती है
@CompoundIndexes(value = {
@CompoundIndex(name = "catalog_idx", def = "{'code' : 1, 'brand' : 1}", unique = true) })
@Document(collection = Catalog.ENTITY)
public class Catalog extends AbstractModel<String> {
private static final long serialVersionUID = 1L;
public static final String ENTITY = "catalog";
@NotNull(message = "Code is required")
@Field("code")
private String code;
@NotNull(message = "Brand is required")
@DBRef(lazy = true)
@Field("brand")
private Brand brand;
}
निम्नलिखित जब मैं mongoTemplate.save(object);
साथ सहेज सकता हूँ मैं 6. के बजाय DB में बनाया से ठीक पहले वस्तुओं के लिए मेरी डिबग लाइनों को बचाने के लिए केवल 2 वस्तुओं को देखने की तरह बचाने होने के लिए।
Catalog [code=StagedCatalog, brand=Brand [code=Brand_3]]
Catalog [code=StagedCatalog, brand=Brand [code=Brand_2]]
Catalog [code=StagedCatalog, brand=Brand [code=Brand_1]]
Catalog [code=OnlineCatalog, brand=Brand [code=Brand_2]]
Catalog [code=OnlineCatalog, brand=Brand [code=Brand_1]]
Catalog [code=OnlineCatalog, brand=Brand [code=Brand_3]]
कोई विचार क्यों? मुझे लगता है कि सूचकांक अद्वितीय चीज किसी भी तरह से काम नहीं कर रही है। मैं code
और brand
unique combination
होना चाहता हूं।
public abstract class AbstractModel<ID extends Serializable> implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private ID id;
}
आपके पास कैटलॉग बनाने वाला कोड है? क्या आप अमूर्त मॉडल में "@id" कॉलम रखते हैं? क्या आप इसे भी लॉग कर सकते हैं? – wargre
@ वार्ग्रे ने किया .... –