Unfortunately i'm already using the 1.1.1.RELEASE. With automatic creation i mean collections are created without having any documents in it - so without any need of them.
I created a small testcase where this behavior happens: Both Documents (MyDocOne and MyDocTwo) contain an @Indexed annotation on a custom field - they also contain a field of type object. So when i create entity myDocOne and myDocTwo - setting myDocTwo.obj = myDocOne and persist myDocTwo - spring creates a collection myDocOne in template2... this is a bit confusing - i hope the following code gives a better overview.
App.java
Code:
@Component
public class App
{
public static void main( String[] args )
{
App app = new App();
ApplicationContextLoader loader = new ApplicationContextLoader();
loader.load(app, "applicationContext.xml");
loader.getApplicationContext();
MongoTemplate template1;
MongoTemplate template2;
try {
template1 = new MongoTemplate(new Mongo("localhost"), "tmp1");
template1.setApplicationContext(loader.getApplicationContext());
template2 = new MongoTemplate(new Mongo("localhost"), "tmp2");
template2.setApplicationContext(loader.getApplicationContext());
MyDocOne one = new MyDocOne("foo", "bar");
template1.save(one);
MyDocTwo two = new MyDocTwo("foo", "baz");
two.setAny(one);
template2.save(two);
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (MongoException e) {
e.printStackTrace();
}
}
}
MyDocOne.java
Code:
@Document
public class MyDocOne {
@Indexed
String a;
String b;
Object any;
public MyDocOne(String a, String b) {
super();
this.a = a;
this.b = b;
}
public String getA() {
return a;
}
public void setA(String a) {
this.a = a;
}
public String getB() {
return b;
}
public void setB(String b) {
this.b = b;
}
public Object getAny() {
return any;
}
public void setAny(Object any) {
this.any = any;
}
}
MyDocTwo.java
Code:
@Document
public class MyDocTwo {
@Indexed
String a;
String b;
Object any;
public MyDocTwo(String a, String b) {
super();
this.a = a;
this.b = b;
}
public String getA() {
return a;
}
public void setA(String a) {
this.a = a;
}
public String getB() {
return b;
}
public void setB(String b) {
this.b = b;
}
public Object getAny() {
return any;
}
public void setAny(Object any) {
this.any = any;
}
}