PSD # OnetoOne

Inability to Tucao.


 

One, a person has an ID number, a person has a life similar to this one is one to one relationship.


Involved two notes:

OneToOne

JoinColumn(

                     name = "name of the database field corresponding to the current entity tables, this field is one relationship in the other primary key, a foreign key field is present in this table,"

                     referencedColumnName = "This is a field name of a database table, the primary key of another table is a foreign key field current table corresponding to the"


 

An example: a student has a table,

@Entity 
the @Table (name = "t_student") 
public class Student { 
	
	@Id 
	@GeneratedValue (Strategy = GenerationType.IDENTITY) 
	the @Column (name = "ID") 
	Private ID Integer; 
	
	the @Column (name = "name") 
	Private String name; 
	
	/ ** 
	 * JoinColumn the name value: the current foreign key of the entity correspondence table 
	 * JoinColumn JoinColumn values of: an entity outside the current key correspondence table referenced by the primary key table 
	 * / 
	@OneToOne 
	@JoinColumn (name = " desk_id ", the referencedColumnName =" ID ") 
	Private Desk Desk; 

	@Override 
	public String toString () { 
		return ReflectionToStringBuilder.toString (the this, ToStringStyle.MULTI_LINE_STYLE); 
	} 
	
}

  

@Entity
@Table(name="t_desk")
public class Desk {
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name="id")
	private Integer id;
	
	@Column(name="name")
	private String name;

	@Override
	public String toString() {
		return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
	}
}

  

Database Table:

 

_

 

Map, whether it is one or other form of mapping, in another dimension into a one-way mapping, as well as bi-directional mapping. Which bidirectional mapping time, JSON serialization will produce an endless loop.

 

Guess you like

Origin www.cnblogs.com/luohaonan/p/11241599.html