Problem loading bootstrap data

126 views
Skip to first unread message

KR

unread,
Nov 1, 2011, 3:06:58 PM11/1/11
to play-framework
I am trying to load some bootstrap data into the database on
Application startup. I have the following class which does that.

-------------------------------------
@OnApplicationStart
public class Bootstrap extends Job<Bootstrap> {
public void doJob() {
try{
if (Installation.count() == 0) {
Logger.debug("Loading data.............");
Fixtures.loadModels("initial-data.yml");
Logger.debug("Done!");
}
}
catch(Exception exc)
{
exc.printStackTrace();
Logger.error("exception caught!!" + exc);
}
}
}
----------------------------------------------------------------

initial-data.yml
---------------------------------
Installation:
name: "HNC-1"
installCode: "HNC-1"
description: "Installation -1"

Installation:
name: "HNC-2"
installCode: "HNC-2"
description: "Installation -2"
-----------------------------------------------------------

Installation model class
--------------------------
@Entity
@Table(name = "installation",uniqueConstraints =
@UniqueConstraint(columnNames = {"name", "install_code"}))
public class Installation extends Model{

@Required
public String name;

@Required
@Column(name="install_code")
public String installCode;

public String description;

public Installation(String name, String installCode, String
description) {
this.name = name;
this.installCode = installCode;
this.description = description;
}
}
---------------------------------------------

The class is getting called fine and the data import seems to happen,
but I don't see anything saved in the database.

Any ideas as to why this is happening?

Thanks in advance.

Jeff

unread,
Nov 1, 2011, 11:50:29 PM11/1/11
to play-framework
Are you seeing NULL values in the DB. I am having a similar problem
with just NULL values being populated. The same .yml file I have works
file when called from tests.

Cheers,
jeff

KR

unread,
Nov 2, 2011, 12:33:54 AM11/2/11
to play-framework
Nope, I see nothing at all in the database. BTW, I am using Play 1.2.3

Mikael

unread,
Nov 2, 2011, 1:27:43 AM11/2/11
to play-fr...@googlegroups.com
Is Installation in the models package? If in a subpackage you need to add it to the yml file.
Also make sure you are using spaces in your yml file, not tabs.

KR

unread,
Nov 2, 2011, 3:33:00 AM11/2/11
to play-framework
Yes, the Installation class is in the models package. The yml file
does have spaces and not tabs. When I deliberately insert tabs, Play
barfs as expected during the import.

Ronald Haring

unread,
Nov 2, 2011, 8:40:45 AM11/2/11
to play-fr...@googlegroups.com
Your classes in the yml need  some kind of identifier, e.g.:

Installation(first):
   name: "HNC-1"
   installCode: "HNC-1"
   description: "Installation -1"

Installation(another):
   name: "HNC-2"
   installCode: "HNC-2"
   description: "Installation -2"

Also the quotes are not needed.

Regards
Ronald

KR

unread,
Nov 2, 2011, 12:37:46 PM11/2/11
to play-framework
Thanks much! That was indeed the issue.
Reply all
Reply to author
Forward
0 new messages