开发者

Changing table schema at run-time in Play! Framework

What is the best way to change database table schema at run time in Pl开发者_JS百科ay! Framework? I get an unspecified amount of columns from a client application and can not have domain objects.


Another option may be to use a schema-less datastore ala mongodb. Seems like there is a mongo module for play, http://www.playframework.org/modules/mongo.


Why not using Apache DDLUtils ?
It's not plugged by default in Play! but I use it in other projects and it's quite useful.
http://db.apache.org/ddlutils/


I think this is exactly what you were looking for

have a look at play snippets

http://www.playframework.org/community/snippets/13

public class Application extends Controller {

@Before
public static void setDBSchema() {
    String schema = "someSchema"; // This can come from a Cache, for example

    Play.configuration.setProperty("hibernate.default_schema", schema);

    JPA.entityManagerFactory = null;
    JPAPlugin plugin = new JPAPlugin();
    plugin.onApplicationStart();
}

...

you just change the configured hibernate schema, and then force the JPAPlugin to restart

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜