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). 
|
1 answer
I can suggest 2 options:
- You may have incorrectly declared relationships between the
Placeandplace_type. For example, there are 2 mappings per table Place :PlaceFullandPlaceShort. Both have a many-to-one relationship on thePlaceTypemapping of thePlaceTypetable.PlaceTypehas feedback, for example, onPlaceFull. If you fetch fromPlaceShort, then Hibernate, after the main entity,PlaceType. Seeing that the feedback fromPlaceTypeleads not to the already selectedPlaceShort, but toPlaceFull, Hibernate will then take a sample fromPlaceFull, and after it again fromPlaceType(since it is also put intoPlaceFull). Seeing that the last selectedPlaceTyperefers to the already selectedPlaceFull, 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. - 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
CDIcomponent 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.
|