开发者

Hibernate design: persistent data plus temporary run-time classes

The question is this. I have a number of persisted objects that I'll pull using Hibernate.

But during the application lifetime I'll create a few objects that do not live outside the running time of an app.

They are temporary, for开发者_StackOverflow中文版 example contain user's choices, and they also hold links to the persistent objects(tables). But as soon as application exited, there's no need in them so temporary objects are destroyed.

How do you think, should those objects be persisted in the same database where normal data is kept?

For example, they may be kept in temporary tables and on exit the data will be erased.

Or they may be created only in memory. Which is better?


You generally don't persist transient objects, unless there are a lot of them gobbling up memory and/or the objects are accessed only rarely, at which point the memory freed by not having them in memory can be used better.

In my opinion, the basis of every design should be simplicity. As simple as possible while as complex as required. Adding Hibernate to those objects adds complexity and potential for trouble, and if it's not necessary then don't do it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜