How to alter the design so that entities don't use injections?

后端 未结 4 1515
没有蜡笔的小新
没有蜡笔的小新 2021-01-18 00:19

I\'ve read and came to realize myself that entities (data objects - for JPA or serialization) with injections in them is a bad idea. Here is my current design (all appropria

4条回答
  •  执念已碎
    2021-01-18 00:41

    A possibility is to remove the property, so it won't be picked up by the serializers. This can be achieved be getting it programmatically.

    private Car2Manager getCar2Manager() {
      CDI.current().select(Car2Manager.class).get();
    }
    

    I would not consider this a clean solution, but it should be a workable "solution"

    Also which might work is using JPA's @Transient:

    @Inject
    @Transient
    Car2Manager manager;
    

    I have not tested this, so it might not work.

提交回复
热议问题