When the application needs to navigate between the associated relationships. how hibernate Gets the policy of the associated object.
How to crawl a policy:
fetchtype.lazy: Lazy loading. When an entity is loaded. Properties that define lazy loading are not immediately loaded from the database.
Fetchtype.eager: Urgent loading, when loading an entity, the attribute that defines the urgency load is immediately loaded from the database.
embodied in the project. I have two entities here. An entity that puts the underlying data. There is also an entity that records the operation.
The relationship between the two entities is a one-to-a relationship, so the primary key in the underlying data is placed in the action record as a foreign key. Query the Operation log table when querying the way the basic table related information out:
Here is the way to annotate:
Private company Company, @OneToOne (Fetch=fetchtype.eager) @JoinColumn (name= "company_id") Publiccompany Getcompany () { Returncompany;} Publicvoid Setcompany (company company) {this.company= Company;}
Capture strategy embodiment: Fetch=fetchtype.eager, here we have to display immediately after the query, so the use of urgent loading.
Here's a question:
Could not Determinetype For:com.tgb.xyb.entity.Company, @ Table:operaterecord, for columns:[ Org.hibernate.mapping.Column (company)]
Workaround: Annotations are placed in Get method Above (note: Originally put annotations on the method)
is because the get method is an external way to get the inner properties of the class. So everything that needs to get a property or object is declared on the get method.
For example, Spring 's dependency injection is also injected from the get method.
The advantage of using a crawl strategy today is. We just need to add this strategy, then the corresponding entity will be associated. We do not need to write the corresponding HQL statement to associate or create a new entity to associate the two entities.
"Hibernate learning"--crawl strategy (annotation method)