I am working with Spring 4 and Hibernate 5. I am doing a test application to manage the events of a fictional theater, and also keep information about those events. I have several classes annotated with @Entity, such as Theater, User, Seat, Room, etc., and many of these classes are related to each other. These classes are already in my database as tables and have stored information.
Now I need to show in my program the amount of entities I have and the relationships between them. But I do not know how to map the database to obtain my entities and their relationships.
I need a method or procedure that returns these values, for example these would be the final results:
Object[] entidades ={Teatro, Sala, Asiento, Persona}
String[] relaciones ={Teatro-Sala, Sala-Asiento, Teatro-Asiento, Asiento-Persona}
Since I use Hibernate and my classes are annotated with @Entity, I've searched for some way to get the information I want but I can not find how to do it. So, in what way can I get my entities and the relationships between them?
Keep in mind that some of the entities can be eliminated eventually, therefore it would be necessary to update the amounts of entities and relationships between them
EDITED
Here I add the code of my DAO, to illustrate an example of how to save it in the database:
@Repository
public class PersonDAOImpl implements PersonDAO {
private static final Logger logger = LoggerFactory.getLogger(PersonDAOImpl.class);
@Autowired
private SessionFactory sessionFactory;
@Override
@Transactional
public void addPerson(Person p) {
Session session = this.sessionFactory.getCurrentSession();
session.persist(p);
logger.info("Person saved successfully, Person Details="+p);
}