开发运行环境:OEPE 12c(12.1.1.1.0)+ WebLogic Server 12c(12.1.1.1.0)+ Oracle Database 10g Express Edition 10.2.0.1
1. 创建Department.java
2. 右键TroubleTicketSystemServer,选择JPA Tools,选择Generate Entities from Java Class
3. 修改Technician.java,增加@ManyToOne,引用Department。
package com.oracle.ticketsystem.beans;
import java.io.Serializable;
import javax.persistence.*;
import java.util.Set;
/**
* The persistent class for the TECHNICIAN database table.
*
*/
@Entity
public class Technician implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private String id;
@ManyToOne()
@JoinColumn(name = "DEPTID", referencedColumnName = "ID")
private Department department;
private String email;
private String name;
private String password;
// bi-directional many-to-one association to Ticket
@OneToMany(mappedBy = "technician")
private Set tickets;
// bi-directional one-to-one association to TechnicianPrivateData
@OneToOne(mappedBy = "technician")
private TechnicianPrivateData technicianPrivateData;
public Technician() {
}
public String getId() {
return this.id;
}
public void setId(String id) {
this.id = id;
}
public Department getDepartment() {
return department;
}
public void setDepartment(Department department) {
this.department = department;
}
public String getEmail() {
return this.email;
}
public void setEmail(String email) {
this.email = email;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return this.password;
}
public void setPassword(String password) {
this.password = password;
}
public Set getTickets() {
return this.tickets;
}
public void setTickets(Set tickets) {
this.tickets = tickets;
}
public TechnicianPrivateData getTechnicianPrivateData() {
return this.technicianPrivateData;
}
public void setTechnicianPrivateData(
TechnicianPrivateData technicianPrivateData) {
this.technicianPrivateData = technicianPrivateData;
}
}
package com.oracle.ticketsystem.beans;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Id;
import javax.persistence.Column;
import javax.persistence.Basic;
import javax.persistence.OneToMany;
import java.util.Set;
@Entity()
@Table(name = "DEPARTMENT", schema = "TROUBLETICKETUSER")
public class Department implements Serializable {
private static final long serialVersionUID = 1L;
@Id()
@Column(name = "ID", unique = true, nullable = false, precision = 22)
private long id;
@Basic()
@Column(name = "NAME", nullable = false, length = 100)
private String name;
@OneToMany(mappedBy = "department")
private Set technicians;
public Department() {
// TODO Auto-generated constructor stub
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Set getTechnicians() {
return technicians;
}
public void setTechnicians(Set technicians) {
this.technicians = technicians;
}
public boolean equals(Object obj) {
if ((this == obj))
return true;
if (!(obj instanceof Department))
return false;
Department castOther = (Department) obj;
if (this.getId() == castOther.getId()) {
return true;
} else {
return false;
}
}
public int hashCode() {
return (new Long(this.getId())).hashCode();
}
}
没有评论:
发表评论