Making Child classes as Non Serializable in java

前端 未结 7 1241
無奈伤痛
無奈伤痛 2020-12-09 16:43

I have a class which implements Serializable. Now I extends this class and I want this extended class to be non Serializable. So how to do it?

For example. I have

7条回答
  •  無奈伤痛
    2020-12-09 17:34

    Answering one of your comment (and assuming you are talking of JPA or Hibernate):

    But Any class which wants its object to be persisted should implement this. and I want my Class B's objects as non persistable.

    If you don't want B to be persistent at all, don't mark it as @Entity. But it doesn't really make sense for B to extend A if B is not a persistent entity IMHO. This would be a bad use of inheritance.

提交回复
热议问题