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

后端 未结 2 2229
情话喂你
情话喂你 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 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).

提交回复
热议问题