Hibernate - Java derived classes for tables

I created the mapping and POJO files in Netbeans instead of writing them myself. Can a derived class be used in place of an inherited class? An example would be something like this:

Person.hbm.xml - mapping file

Person.java - generated class (strategy class per table)

PersonExtended - class that extends Person.java

So when I create a new object:

PersonExtended personextended = new PersonExtended(<parameters>);

Can I call methods like:

session.save(personextended) or session.delete(personextended)

?

Is this script reasonable or should I add the code I need to the generated class? Thanks in advance for your help or suggestions.

------- -------- Edit

In my database, I do not have a typical structure that could appear as inheritance. I just want additional methods to be separated from the main java class for the object.

Best regards, Insolence.

+3
1

, hbm.xml. , Hibernate , . , " " "" ".

hbm-xml <subclass> <joined-subclass>

hbm.xml, session.save(new PersonExtended()) sth.

: http://docs.jboss.org/hibernate/core/3.3/reference/en/html/inheritance.html

, ..

+2

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


All Articles