Ich habe das Modell wie folgtFrühling mongodb Vorlage speichert in demselben Objekt
@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;
}
Wenn ich mit mongoTemplate.save(object);
sparen sehe ich nur zwei Objekte in DB erstellt statt 6. Kurz bevor meine Debug-Linien für Objekte speichern gespeichert werden.
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]]
Irgendwelche Ideen warum? Ich finde das Index-Einmalige funktioniert irgendwie nicht. Ich möchte code
und brand
zu unique combination
sein.
public abstract class AbstractModel<ID extends Serializable> implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private ID id;
}
Sie haben Code, der Katalog erstellen? Hast du eine "@id" -Spalte im abstrakten Modell? Kannst du das auch protokollieren? – wargre
@wargre tat .... –