0
A
回答
0
我得到了如何創建休眠的唯一約束的答案....
Office.java類
@Entity
@Table(name="OFFICE")
public class Office {
@Id
@Column(name = "ID", unique = true, nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column(name = "OFFICE_NAME", length=30)
private String officeName;
@Column(name = "DESCRPTION", length=5000)
private String description;
@OneToMany(mappedBy="office", targetEntity=Emplyee.class, cascade=CascadeType.ALL)
private Set<Emplyee> emplyees = new HashSet<Emplyee>();
/**
* @return the id
*/
public long getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(long id) {
this.id = id;
}
/**
* @return the officeName
*/
public String getOfficeName() {
return officeName;
}
/**
* @param officeName the officeName to set
*/
public void setOfficeName(String officeName) {
this.officeName = officeName;
}
/**
* @return the description
*/
public String getDescription() {
return description;
}
/**
* @param description the description to set
*/
public void setDescription(String description) {
this.description = description;
}
/**
* @return the emplyees
*/
public Set<Emplyee> getEmplyees() {
return emplyees;
}
/**
* @param emplyees the emplyees to set
*/
public void setEmplyees(Set<Emplyee> emplyees) {
this.emplyees = emplyees;
}
}
Employee.java類
@Entity
@Table(name="EMPLOYEE", uniqueConstraints={@UniqueConstraint(columnNames={"OFFICE_ID","EMPLOYEE_NUMBER"})})
public class Emplyee {
@Id
@Column(name = "ID", unique = true, nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column(name = "FIRST_NAME", nullable=false, length=30)
private String firstName;
@Column(name = "MIDDLE_NAME",length=30)
private String middleName;
@Column(name = "LAST_NAME", nullable=false, length=30)
private String lastName;
@Column(name = "EMPLOYEE_NUMBER", nullable=false, length=20)
private String employeeNumber;
@ManyToOne
@JoinColumn(name="OFFICE_ID")
private Office office;
/**
* @return the id
*/
public long getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(long id) {
this.id = id;
}
/**
* @return the firstName
*/
public String getFirstName() {
return firstName;
}
/**
* @param firstName the firstName to set
*/
public void setFirstName(String firstName) {
this.firstName = firstName;
}
/**
* @return the middleName
*/
public String getMiddleName() {
return middleName;
}
/**
* @param middleName the middleName to set
*/
public void setMiddleName(String middleName) {
this.middleName = middleName;
}
/**
* @return the lastName
*/
public String getLastName() {
return lastName;
}
/**
* @param lastName the lastName to set
*/
public void setLastName(String lastName) {
this.lastName = lastName;
}
/**
* @return the employeeNumber
*/
public String getEmployeeNumber() {
return employeeNumber;
}
/**
* @param employeeNumber the employeeNumber to set
*/
public void setEmployeeNumber(String employeeNumber) {
this.employeeNumber = employeeNumber;
}
/**
* @return the office
*/
public Office getOffice() {
return office;
}
/**
* @param office the office to set
*/
public void setOffice(Office office) {
this.office = office;
}
}
但我可以使用這種註解在班級上的表.... uniqueConstraints = {@ UniqueConstraint(columnNames = {「FIELD1」,「FIELD2」})}。
相關問題
- 1. Neo4JClient創建唯一約束
- 2. 如何在父表上創建約束子表的約束?
- 3. 在兩個表格的兩列上創建唯一約束
- 4. 如何創建一個唯一的約束表?
- 5. Hibernate的複雜的唯一約束
- 6. 唯一約束在NON-NULL列上的唯一約束
- 7. 如何在布爾值上創建唯一約束2列?
- 8. 如何在多個表中創建條件唯一約束?
- 9. 如何在Doctrine2的YML中創建唯一約束?
- 10. DataTable上的唯一約束
- 11. 表列上的唯一約束條件
- 12. SQLite表約束 - 在多列上唯一
- 13. 創建唯一約束最初禁用
- 14. 爲2列創建唯一約束
- 15. Hibernate @Id和oracle唯一約束
- 16. Hibernate session.flush()導致ORA-00001:唯一約束
- 17. 定義在表的同一列上的主鍵約束和唯一約束
- 18. 如何在SQL Server中創建多列唯一約束
- 19. 如何在SQL Server 2005中創建複合唯一約束
- 20. 我們如何在lift-mapper中創建唯一約束
- 21. 如何在laravel 5.2中創建唯一約束?
- 22. 如何在db2中創建複合唯一約束
- 23. 如何在sql server中創建唯一約束?
- 24. 如何在GreenDAO中創建組合唯一鍵約束
- 25. 如何在Elasticsearch數據庫中創建唯一約束?
- 26. 如何在這種情況下爲hibernate定義唯一約束?
- 27. 在外鍵約束列上創建非唯一索引
- 28. 唯一約束
- 29. SQL Server 2005如何創建唯一約束?
- 30. Grails:我如何爲多列創建命名唯一約束?