I am trying to port to YABE in play1.2.4 to play 2.0.4 Java. For that I created a initial-data.yml and tried to load it with Global.java
#Users users: - !!models.User email: [email protected] password: secret fullname: Bob isAdmin: true #Posts posts: - !!models.Post id: 1 title: About the model layer postedAt: 2009-06-14 author: - !!models.User email: [email protected] content: > The model has a central position in a Play! application. Cut....
My Global.java is below
public void onStart(Application app) {
InitialData.insert(app);
}
static class InitialData {
public static void insert(Application app) {
if(Ebean.find(User.class).findRowCount() == 0) {
Map<String, List<Object>> all = (Map<String, List<Object>>)Yaml.load("initial-data.yml");
Ebean.save(all.get("users"));
Ebean.save(all.get("posts"));
Ebean.save(all.get("comments"));
}
}
}
While loading I am getting following errors
ConstructorException: null; Can't construct a java object for tag:yaml.org,2002:models.Post; exception=Cannot create property=author for JavaBean=models.Post@1; No suitable constructor with 3 arguments found for class models.User
org.yaml.snakeyaml.constructor.ConstructorException: null; Can't construct a java object for tag:yaml.org,2002:models.Post; exception=Cannot create property=author for JavaBean=models.Post@1; No suitable constructor with 3 arguments found for class models.User org.yaml.snakeyaml.constructor.Constructor$ConstructYamlObject.construct(Constructor.java:333) org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:183) org.yaml.snakeyaml.constructor.BaseConstructor.constructSequenceStep2(BaseConstructor.java:277) org.yaml.snakeyaml.constructor.BaseConstructor.constructSequence(BaseConstructor.java:248) org.yaml.snakeyaml.constructor.SafeConstructor$ConstructYamlSeq.construct(SafeConstructor.java:440) org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:183) org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping2ndStep(BaseConstructor.java:326) org.yaml.snakeyaml.constructor.SafeConstructor.constructMapping2ndStep(SafeConstructor.java:143) org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping(BaseConstructor.java:307) org.yaml.snakeyaml.constructor.SafeConstructor$ConstructYamlMap.construct(SafeConstructor.java:459) org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:183) org.yaml.snakeyaml.constructor.BaseConstructor.constructDocument(BaseConstructor.java:142) org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:128) org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:480) org.yaml.snakeyaml.Yaml.load(Yaml.java:411)
Any Idea why this happens?
Manuel, Thanks for the help.
When I slightly modified the YAML i got it working, I just removed the "-", which is in front of the "model.class"
#Users users: - !!models.User email: [email protected] password: secret fullname: Bob isAdmin: true #Posts posts: - !!models.Post id: 1 title: About the model layer postedAt: 2009-06-14 author: !!models.User email: [email protected] content: > The model has a central position in a Play! application. Cut....
Any idea what "-" stands for?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With