hibernate one-to-many

*, Hibernate one-to-many configuration startup prerequisite

Existing entity person and entity car, the relationship between the two is one-to-many

 

*, Note: At this time, the primary key of person should be referenced by the entity car as a foreign key

property name="personId" type="java.util.Integer">
	<column name="PERSON_ID"></column>
</property>

   

When person needs to manage the entity class of car or lazily load one or more entity classes

--Add the idcare entity attribute to the entity class of person

private List<Car> cars;
get/set

 

--Add the many-to-one attribute to the person's hbm configuration file

<bag name="cars" lazy="true" inverse="true" cascade="none">
	<key column="person_id is the primary key ID of the person class in the car table" not-null="true" />
	<one-to-many class="com.car" />
</bag>

 

On the contrary: you can configure the above information in the entity class of idcard and hbm. If configured at the same time, it is also called two-way one-to-one association

Whether it is correct or not, it still needs to be discussed, and if it is inappropriate, please let me know~

-------------------------------------------------- Small Bug--------------------------------------------------------- -------

*、Could not initialize proxy - the owning Session was closed

See: http://lbovinl.iteye.com/blog/2373492

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326474732&siteId=291194637