• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Non-Entity Classes in the Entity Inheritance Hierarchy

 
Ram Venkat
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Explanation from Spec

The non-entity superclass serves for inheritance of behavior only. The state of a non-entity
superclass is NOT PERSISTENT. Any state inherited from non-entity superclasses is nonpersistent
in an inheriting entity class.


My quesion : If we are not able to save state inherited from Non-Entity superlass is Non-Persistent in an inherting entity class. Then what is use of this design?
 
nitin pai
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you also check the example given in the spec.

You can think these classes as some helper classes which might be used to provide some logic not related to your persistance context. Maybe something like validation of incrementing a counter variable as shown in the spec example.

Let's say you might already have logic sitting in a jar file. How would you use it in an entity? Non-entity classes would help you to use such "behavior" logic in your entity classes.
 
Sergio Tridente
Ranch Hand
Posts: 329
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at the @MappedSuperclass annotation.

In short, if you annotate your superclass with the @mappedSuperclass annotation, then any entity subclass inherits the persistance properties of the base class.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic