mam model jak poWiosna MongoDB szablon zapisuje w tym samym obiekcie
@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;
}
Kiedy zrobić uratować z mongoTemplate.save(object);
widzę tylko 2 obiekty utworzone w DB zamiast 6. Tuż przed uratować moje wiersze debugowania dla obiektów być uratowanym.
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]]
Jakieś pomysły, dlaczego? Czuję, że unikatowa funkcja Indeksu nie działa w jakiś sposób. Chcę code
i brand
być unique combination
.
public abstract class AbstractModel<ID extends Serializable> implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private ID id;
}
masz kod, który tworzy katalog? Czy masz kolumnę "@id" w abstrakcyjnym modelu? możesz to również zarejestrować? – wargre
@wargre did .... –