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

后端 未结 2 2212
情话喂你
情话喂你 2021-02-20 07:15

I am working on a Wicket-based web app on Java EE.

I am trying to find a way to ensure that any entities used as model objects are always attached to the current EntityM

相关标签:
2条回答
  • 2021-02-20 07:58

    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..

    0 讨论(0)
  • 2021-02-20 08:05

    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).

    0 讨论(0)
提交回复
热议问题