下面是我的serviceconcontract .java
package com.cerebro.model.domain;
import java.io.Serializable;
import java.util.logging.Logger;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.Digits;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.hibernate.validator.constraints.NotEmpty;
import com.google.common.base.MoreObjects;
@Entity
@Table(name = "service_contract")
public class ServiceContract extends AbstractBaseEntity implements Identifiable<Long>, Serializable {
private static final long serialVersionUID = 1L;
private static final Logger log = Logger.getLogger(ServiceContract.class.getName());
// Raw attributes
private Long id;
private String name;
private String description;
private String type;
private Long contractStart;
private Long contractEnd;
private Boolean isrepeated;
private Boolean autoApproved;
private Boolean staffAutoApproved;
private String status;
// Many to one
private HospitalUnit unit;
private Staff preferredStaff;
private Specialty specialty;
private SkillMaster skill;
private ServiceLocation ServiceLocation;
private ServiceSchedule ServiceSchedule;
private Hospital hospital;
@Override
public String entityClassName() {
return ServiceContract.class.getSimpleName();
}
// -- [id] ------------------------
@Override
@Column(name = "id", precision = 19)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "service_contract_id_seq")
@SequenceGenerator(name = "service_contract_id_seq", sequenceName = "service_contract_id_seq", allocationSize = 1)
@Id
public Long getId() {
return id;
}
@Override
public void setId(Long id) {
this.id = id;
}
public ServiceContract id(Long id) {
setId(id);
return this;
}
@Override
@Transient
public boolean isIdSet() {
return id != null;
}
// -- [name] ------------------------
@NotEmpty
@Size(max = 256)
@Column(name = "name", nullable = false, length = 256)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public ServiceContract name(String name) {
setName(name);
return this;
}
// -- [description] ------------------------
@NotEmpty
@Size(max = 500)
@Column(name = "description", nullable = false, length = 500)
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public ServiceContract description(String description) {
setDescription(description);
return this;
}
// -- [type] ------------------------
@NotEmpty
@Size(max = 50)
@Column(name = "`type`", nullable = false, length = 50)
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public ServiceContract type(String type) {
setType(type);
return this;
}
// -- [contractStart] ------------------------
@Digits(integer = 19, fraction = 0)
@NotNull
@Column(name = "contract_start", nullable = false, precision = 19)
public Long getContractStart() {
return contractStart;
}
public void setContractStart(Long contractStart) {
this.contractStart = contractStart;
}
public ServiceContract contractStart(Long contractStart) {
setContractStart(contractStart);
return this;
}
// -- [contractEnd] ------------------------
@Digits(integer = 19, fraction = 0)
@Column(name = "contract_end", precision = 19)
public Long getContractEnd() {
return contractEnd;
}
public void setContractEnd(Long contractEnd) {
this.contractEnd = contractEnd;
}
public ServiceContract contractEnd(Long contractEnd) {
setContractEnd(contractEnd);
return this;
}
// -- [isrepeated] ------------------------
@NotNull
@Column(name = "isrepeated", nullable = false, length = 1)
public Boolean getIsrepeated() {
return isrepeated;
}
public void setIsrepeated(Boolean isrepeated) {
this.isrepeated = isrepeated;
}
public ServiceContract isrepeated(Boolean isrepeated) {
setIsrepeated(isrepeated);
return this;
}
// -- [autoApproved] ------------------------
@NotNull
@Column(name = "auto_approved", nullable = false, length = 1)
public Boolean getAutoApproved() {
return autoApproved;
}
public void setAutoApproved(Boolean autoApproved) {
this.autoApproved = autoApproved;
}
public ServiceContract autoApproved(Boolean autoApproved) {
setAutoApproved(autoApproved);
return this;
}
// -- [staffAutoApproved] ------------------------
@NotNull
@Column(name = "staff_auto_approved", nullable = false, length = 1)
public Boolean getStaffAutoApproved() {
return staffAutoApproved;
}
public void setStaffAutoApproved(Boolean staffAutoApproved) {
this.staffAutoApproved = staffAutoApproved;
}
public ServiceContract staffAutoApproved(Boolean staffAutoApproved) {
setStaffAutoApproved(staffAutoApproved);
return this;
}
// -- [createdts] ------------------------
public ServiceContract createdts(Long createdts) {
setCreatedts(createdts);
return this;
}
// -- [updatedts] ------------------------
public ServiceContract updatedts(Long updatedts) {
setUpdatedts(updatedts);
return this;
}
// -- [createdby] ------------------------
public ServiceContract createdby(String createdby) {
setCreatedby(createdby);
return this;
}
// -- [status] ------------------------
@NotEmpty
@Size(max = 2147483647)
@Column(name = "status", nullable = false, length = 2147483647)
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public ServiceContract status(String status) {
setStatus(status);
return this;
}
// -----------------------------------------------------------------
// Many to One support
// -----------------------------------------------------------------
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// many-to-one: ServiceContract.unit ==> HospitalUnit.id
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@NotNull
@JoinColumn(name = "unit_id", nullable = false)
@ManyToOne
public HospitalUnit getUnit() {
return unit;
}
/**
* Set the {@link #unit} without adding this ServiceContract instance on the
* passed {@link #unit}
*/
public void setUnit(HospitalUnit unit) {
this.unit = unit;
}
public ServiceContract unit(HospitalUnit unit) {
setUnit(unit);
return this;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// many-to-one: ServiceContract.preferredStaff ==> Staff.id
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@JoinColumn(name = "preferred_staff_id")
@ManyToOne
public Staff getPreferredStaff() {
return preferredStaff;
}
/**
* Set the {@link #preferredStaff} without adding this ServiceContract
* instance on the passed {@link #preferredStaff}
*/
public void setPreferredStaff(Staff preferredStaff) {
this.preferredStaff = preferredStaff;
}
public ServiceContract preferredStaff(Staff preferredStaff) {
setPreferredStaff(preferredStaff);
return this;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// many-to-one: ServiceContract.specialty ==> Specialty.id
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@NotNull
@JoinColumn(name = "specialty_id", nullable = false)
@ManyToOne
public Specialty getSpecialty() {
return specialty;
}
/**
* Set the {@link #specialty} without adding this ServiceContract instance
* on the passed {@link #specialty}
*/
public void setSpecialty(Specialty specialty) {
this.specialty = specialty;
}
public ServiceContract specialty(Specialty specialty) {
setSpecialty(specialty);
return this;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// many-to-one: ServiceContract.skill ==> SkillMaster.id
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@NotNull
@JoinColumn(name = "skill_id", nullable = false)
@ManyToOne
public SkillMaster getSkill() {
return skill;
}
/**
* Set the {@link #skill} without adding this ServiceContract instance on
* the passed {@link #skill}
*/
public void setSkill(SkillMaster skill) {
this.skill = skill;
}
public ServiceContract skill(SkillMaster skill) {
setSkill(skill);
return this;
}
@OneToOne(mappedBy = "ServiceContract", cascade = CascadeType.PERSIST)
public ServiceLocation getServiceLocation() {
return ServiceLocation;
}
public void setServiceLocation(ServiceLocation ServiceLocation) {
this.ServiceLocation = ServiceLocation;
}
public ServiceContract serviceLocation(ServiceLocation ServiceLocation) {
setServiceLocation(ServiceLocation);
return this;
}
@OneToOne(mappedBy = "ServiceContract", cascade = CascadeType.PERSIST)
public ServiceSchedule getServiceSchedule() {
return ServiceSchedule;
}
public void setServiceSchedule(ServiceSchedule ServiceSchedule) {
this.ServiceSchedule = ServiceSchedule;
}
public ServiceContract serviceSchedule(ServiceSchedule ServiceSchedule) {
setServiceSchedule(ServiceSchedule);
return this;
}
@NotNull
@JoinColumn(name = "hospital_id", nullable = false)
@OneToOne
public Hospital getHospital() {
return hospital;
}
public void setHospital(Hospital hospital) {
this.hospital = hospital;
}
public ServiceContract hospital(Hospital hospital) {
setHospital(hospital);
return this;
}
/**
* Apply the default values.
*/
public ServiceContract withDefaults() {
return this;
}
/**
* Equals implementation using a business key.
*/
@Override
public boolean equals(Object other) {
return this == other || (other instanceof ServiceContract && hashCode() == other.hashCode());
}
private IdentifiableHashBuilder identifiableHashBuilder = new IdentifiableHashBuilder();
@Override
public int hashCode() {
return identifiableHashBuilder.hash(log, this);
}
/**
* Construct a readable string representation for this ServiceContract
* instance.
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return MoreObjects.toStringHelper(this) //
.add("id", getId()) //
.add("name", getName()) //
.add("description", getDescription()) //
.add("type", getType()) //
.add("contractStart", getContractStart()) //
.add("contractEnd", getContractEnd()) //
.add("isrepeated", getIsrepeated()) //
.add("autoApproved", getAutoApproved()) //
.add("staffAutoApproved", getStaffAutoApproved()) //
.add("createdts", getCreatedts()) //
.add("updatedts", getUpdatedts()) //
.add("createdby", getCreatedby()) //
.add("status", getStatus()) //
.toString();
}
}
和ServiceLocation.java
package com.cerebro.model.domain;
import java.io.Serializable;
import java.util.logging.Logger;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.hibernate.validator.constraints.NotEmpty;
import com.google.common.base.MoreObjects;
@Entity
@Table(name = "service_location")
public class ServiceLocation extends AbstractBaseEntity implements Identifiable<Long>, Serializable {
private static final long serialVersionUID = 1L;
private static final Logger log = Logger.getLogger(ServiceLocation.class.getName());
// Raw attributes
private Long id;
private String address1;
private String address2;
private String city;
private String state;
private String zip;
private String country;
// Many to one
private ServiceContract ServiceContract;
@Override
public String entityClassName() {
return ServiceLocation.class.getSimpleName();
}
// -- [id] ------------------------
@Override
@Column(name = "id", precision = 19)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "service_location_id_seq")
@SequenceGenerator(name = "service_location_id_seq", sequenceName = "service_location_id_seq", allocationSize = 1)
@Id
public Long getId() {
return id;
}
@Override
public void setId(Long id) {
this.id = id;
}
public ServiceLocation id(Long id) {
setId(id);
return this;
}
@Override
@Transient
public boolean isIdSet() {
return id != null;
}
// -- [address1] ------------------------
@NotEmpty
@Size(max = 500)
@Column(name = "address1", nullable = false, length = 500)
public String getAddress1() {
return address1;
}
public void setAddress1(String address1) {
this.address1 = address1;
}
public ServiceLocation address1(String address1) {
setAddress1(address1);
return this;
}
// -- [address2] ------------------------
@Size(max = 500)
@Column(name = "address2", length = 500)
public String getAddress2() {
return address2;
}
public void setAddress2(String address2) {
this.address2 = address2;
}
public ServiceLocation address2(String address2) {
setAddress2(address2);
return this;
}
// -- [city] ------------------------
@NotEmpty
@Size(max = 50)
@Column(name = "city", nullable = false, length = 50)
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public ServiceLocation city(String city) {
setCity(city);
return this;
}
// -- [state] ------------------------
@NotEmpty
@Size(max = 100)
@Column(name = "`state`", nullable = false, length = 100)
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public ServiceLocation state(String state) {
setState(state);
return this;
}
// -- [zip] ------------------------
@NotEmpty
@Size(max = 50)
@Column(name = "zip", nullable = false, length = 50)
public String getZip() {
return zip;
}
public void setZip(String zip) {
this.zip = zip;
}
public ServiceLocation zip(String zip) {
setZip(zip);
return this;
}
// -- [country] ------------------------
@Size(max = 50)
@Column(name = "country", length = 50)
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public ServiceLocation country(String country) {
setCountry(country);
return this;
}
// -- [createdts] ------------------------
public ServiceLocation createdts(Long createdts) {
setCreatedts(createdts);
return this;
}
// -- [updatedts] ------------------------
public ServiceLocation updatedts(Long updatedts) {
setUpdatedts(updatedts);
return this;
}
// -- [createdby] ------------------------
public ServiceLocation createdby(String createdby) {
setCreatedby(createdby);
return this;
}
// -----------------------------------------------------------------
// Many to One support
// -----------------------------------------------------------------
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// many-to-one: ServiceLocation.serviceContract ==> ServiceContract.id
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// @NotNull
// @JoinColumn(name = "service_contract_id", nullable = false)
// @ManyToOne
@OneToOne
@JoinColumn(name = "service_contract_id")
public ServiceContract getServiceContract() {
return ServiceContract;
}
/**
* Set the {@link #serviceContract} without adding this ServiceLocation instance on the passed {@link #serviceContract}
*/
public void setServiceContract(ServiceContract ServiceContract) {
this.ServiceContract = ServiceContract;
}
public ServiceLocation serviceContract(ServiceContract ServiceContract) {
setServiceContract(ServiceContract);
return this;
}
/**
* Apply the default values.
*/
public ServiceLocation withDefaults() {
return this;
}
/**
* Equals implementation using a business key.
*/
@Override
public boolean equals(Object other) {
return this == other || (other instanceof ServiceLocation && hashCode() == other.hashCode());
}
private IdentifiableHashBuilder identifiableHashBuilder = new IdentifiableHashBuilder();
@Override
public int hashCode() {
return identifiableHashBuilder.hash(log, this);
}
/**
* Construct a readable string representation for this ServiceLocation instance.
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return MoreObjects.toStringHelper(this) //
.add("id", getId()) //
.add("address1", getAddress1()) //
.add("address2", getAddress2()) //
.add("city", getCity()) //
.add("state", getState()) //
.add("zip", getZip()) //
.add("country", getCountry()) //
.add("createdts", getCreatedts()) //
.add("updatedts", getUpdatedts()) //
.add("createdby", getCreatedby()) //
.toString();
}
}
当我部署时,我一直得到:org.hibernate.AnnotationException: Unknown mappedBy in: com.cerebro.model.domain.ServiceContract。serviceLocation,引用属性未知我错过了什么?
mappedBy
属性名应该以小写字母's'
开头:
@OneToOne(mappedBy = "serviceContract", cascade = CascadeType.PERSIST)
public ServiceLocation getServiceLocation() {
return ServiceLocation;
}
即使字段ServiceLocation.ServiceContract
的名称以大写'S'
开头,您正在注释getter方法,JPA规范表明属性名称将使用JavaBean约定从getter方法名称派生(即从方法名称中剥离'get'
并将第一个字符转换为小写字母,除非它后面跟着另一个大写字母)。