Common JPA field

Is it possible to save the general field?

I have this property in class Entity

...
private T payload;
...

T extends EventMessagePayload

and

public interface StringPayload extends EventMessagePayload{ 
    String getPayload();
}

In my application, I save the field only when it is of type String, and during the save operation everything works fine.

When I read an object instead of a JPA, try creating an object String, but instead StringPaylod. Is there a way to intercept the creation and handle the marshalling of the object?

+3
source share
2 answers

JPA itself does not allow this, but your JPA implementation may allow it. We once did this with Hibernate, and it collapses to implement our own EntityTuplizer (and HibernateInterceptor to display your objects back to HibernateEntities).

+3
source

We can. if TimplementsSerializable

@Entity
public class IgsSubject extends BasicObject implements Serializable{

    private static final long serialVersionUID = -5387429446192609471L;
0
source

Source: https://habr.com/ru/post/1784762/


All Articles