Hibernate with one request several times pulls one and tighter essence. In different cases in different ways, once twice, the second three times. Who can say what it is connected with? And is this a problem in principle or maybe I misunderstood the work of the hibernate and in fact everything is correct I add a screen so you can see the requests to the database in the console. Also, if this is really a repeated reference to the database, tell me what exactly should be added to the question (dao, services, models). enter image description here

    1 answer 1

    I can suggest 2 options:

    1. You may have incorrectly declared relationships between the Place and place_type . For example, there are 2 mappings per table Place : PlaceFull and PlaceShort . Both have a many-to-one relationship on the PlaceType mapping of the PlaceType table. PlaceType has feedback, for example, on PlaceFull . If you fetch from PlaceShort , then Hibernate, after the main entity, PlaceType . Seeing that the feedback from PlaceType leads not to the already selected PlaceShort , but to PlaceFull , Hibernate will then take a sample from PlaceFull , and after it again from PlaceType (since it is also put into PlaceFull ). Seeing that the last selected PlaceType refers to the already selected PlaceFull , Hibernate will stop there. This will result in a consistent sample: PlaceShort -> PlaceType -> PlaceFull -> PlaceType . The fact that the number of requests varies may indicate that some records in the Place table may not have references to the place_type table, which is why Hibernate stops immediately.
    2. There may be issues with multithreading. There is hardly anything you can tell - see and debug yourself. If you lay out a project that allows you to reproduce the problem, maybe someone will take up testing and search for errors. If the process is called from some CDI component of the application level that is started when the server starts, make sure that the database accesses are not made from the designer, but, for example, from the method marked as @PostConstruct . Also, the problem may be when an external component accesses a server component — the server can create and put several component instances at once in the component pool, but only one of them should be sent for processing the request. If at the same time the component selects from the database in the constructor or in @PostConstruct , then the call to the database will be performed regardless of whether the call was made to the business method of the component.

    If my options do not solve the problem, add the source code to the question: at least the mappings and the source code that does the reading.