On the urgent loading problem of Hibernate (multiple foreign key Association)

The database structure is as follows

Foreign key member in strategy_ ID (associated member table) foreign key strategy_ Category (associated with category table) and foreign key position in member table_ ID (associated positions table)

If the foreground page directly queries the contents of the stategy table, our HQL statement says this

Stringhql="FromStrategywhereid=:id";

The console will report a nosession error. This is because hibernate is lazy by default. The associated object will be loaded only when we need it. Here, such an error will be reported only when the session has been closed when we need to get the properties in the associated object in the foreground

So how to solve it

It is recommended to use the method of left join fetch to load objects instead of changing the default lazy load in the annotation to urgent load, which will be very inefficient

The statement is as follows

It should be noted here that because the positions table is associated with the associated member table, it needs to be loaded together. Another thing to note is that the s.id here must be written like this, because the primary key name of each table here is ID. if it does not indicate that the system cannot recognize it

summary

The above is all about the urgent loading problem of Hibernate (multiple foreign key Association) in this paper. I hope it will be helpful to you. Interested friends can continue to refer to other related topics on this site. If there are deficiencies, please leave a message to point out. Thank you for your support!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>