How do I keep entities (or their associations) attached to the current persistence context across multiple requests (using Wicket & JPA)?

和自甴很熟 提交于 2019-12-04 01:37:12

I cases like this I usually create a DTO keeping all the data I need to create an entity. If you need to reference existing entities - pass them to your forms/panels as separate models. When the form is submitted you can then:

  • perform the validation
  • create a new entity from DTO that was edited
  • inject references to other entities that you have stored in those separate LDM models.
  • persist the entity.

It's a bit of hassle but does actually work.

Conversations spanning multiple requests are not available in pure wicket and probably will never be - this is not wicket's area.

Seam supports long conversations and it does support wicket (I have never used seam - I cannot advice you on this one).

Seems to be kindof an old post..

I hope it will help some others anyway:

First: Your LDM is a bit useless, because the entity property is not transient. Therefore your entity gets serialised to your session store and thats not the meaning of an LDM. It's supposed to minimize the serialization size of any modeldata.

Second: Your problem isn't a real problem, cause what you need, is what you already have: You want to prepare an Entity over several pages to be finally stored in your database (some wizard or so..). Now, that your LDM is fully serialized to your session store between the requests of the client, your entity and its edited data survives multiple requests, no need for any merging. As soon, as your wizard is finished, you simply persist the hole entity. Before the entity is in its final state, it doesn't make sense to persist anything (though it survives over requests in your session store).

You don't even need the LDM for this kind of funcionality..

Simply give the entity as parameter to the next page, where the user may complete its data.

Hope you solved this problem already..

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!