Added event on saving User cascade save EmailAddress
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package org.baeldung.config;
|
||||
|
||||
import org.baeldung.event.CascadingMongoEventListener;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.mongodb.config.AbstractMongoConfiguration;
|
||||
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
|
||||
@@ -25,4 +27,9 @@ public class MongoConfig extends AbstractMongoConfiguration {
|
||||
public String getMappingBasePackage() {
|
||||
return "org.baeldung";
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CascadingMongoEventListener cascadingMongoEventListener(){
|
||||
return new CascadingMongoEventListener();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package org.baeldung.model;
|
||||
|
||||
import org.baeldung.annotation.CascadeSave;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.index.CompoundIndex;
|
||||
import org.springframework.data.mongodb.core.index.CompoundIndexes;
|
||||
import org.springframework.data.mongodb.core.index.IndexDirection;
|
||||
import org.springframework.data.mongodb.core.index.Indexed;
|
||||
import org.springframework.data.mongodb.core.mapping.DBRef;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
@@ -16,11 +16,14 @@ public class User {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
@Indexed(direction = IndexDirection.ASCENDING)
|
||||
private String name;
|
||||
|
||||
private Integer age;
|
||||
@DBRef
|
||||
@Indexed
|
||||
@Field("email")
|
||||
@CascadeSave
|
||||
|
||||
private EmailAddress emailAddress;
|
||||
|
||||
public String getId() {
|
||||
|
||||
Reference in New Issue
Block a user