开发者

create fixture using hibernate(not import.sql method)

Is there a way to use java code and those hibernate entity classes to create fixture data.

开发者_如何学C

I find using import.sql is not good when it comes to database migration


Since you are using hibernate, the way to create sample data is to use hibernate itself to create it. You have two options:

  • generate random data - look from 1 to X, instantiate entities and set random values, then save each entity
  • predefined data - use some meta format, like .properties, .json or .xml to define field=value pairs, parse that file, instantiate entities for each record, set the fields, and save it.

That way your data generation is tied to your entity model, and when the model changes, your data won't become out-of-sync.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜