@OnetoOne关系中的JPA外键未显示在查询中

时间:2019-03-04 19:49:45

标签: spring-boot jpa one-to-one

我试图在FacilityGeneral和FacilityLocation实体之间创建一个@OneToOne关系,其中FacilityLocation实体拥有外键。我能够启动应用程序而没有任何错误,但是当我使用内置的findAll()语句查询FacilityGeneral实体时,命名字段(外键)未显示为字段值。这些值确实存在于数据库表中。这是怎么回事?

设施一般实体:

@Entity
public class FacilityGeneral {

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "facilityGenIdSeq")
@SequenceGenerator(name = "facilityGenIdSeq", initialValue = 567, allocationSize = 1)
@Column(updatable = false, unique = true)
private Long generalIdPk;

@NotBlank(message = "Facility Name is required")
private String facilityName;

@Column(length = 200)
private String facilityNameHistory;

@Column(length = 15)
private String phoneNumber;

private Integer phoneExtension;
@Column(length = 50)
private String facilityType;
@Column(length = 50)
private String facilityApprovalType;
@Column(length = 50)
private String landfillClass;
@Column(length = 50)
private String facilityStatus;
@Column(length = 50)
private String firstReceiptOfWaste; //This is a String because legacy data is inconsistent (some only years, others full dates)

@Column(length = 50)
private String ownershipType;
@Column(length = 50)
private String dshwStaffPerson;
@Column(length = 50)
private String legAndGovApproval;

@JsonFormat(pattern = "MM/dd/yyyy")
private LocalDate dateOfLegApproval;

@JsonFormat(pattern = "MM/dd/yyyy")
private LocalDate dateOfGovApproval;

@Column(length = 200)
private String govLegHyperlink;
@JsonFormat(pattern = "MM/dd/yyyy")
private LocalDate localApprovalDate;
private String localApprovalDescription;
@Column(length = 500)
private String comments;
@Column(length = 50)
private String tireRegistrationNumber;
@Column(length = 50)
private String tireRegistrationFeePaid;
@Column(length = 50)
private String tireRegAppTrackingNumber; /*Tire Registration Application Tracking Numner*/
@JsonFormat(pattern = "MM/dd/yyyy")
private LocalDate tireRegInsActivationDate; /*Tire Registration Insurance Application Date*/
@JsonFormat(pattern = "MM/dd/yyyy")
private LocalDate tireRegInsExpirationDate; /*Tire Registration Insurance Expiration Data*/

@OneToOne(fetch = FetchType.EAGER, mappedBy = "facilityGeneral", cascade = 
CascadeType.PERSIST)
private FacilityLocation location;

设施位置实体

@Entity
public class FacilityLocation {

@Id
@SequenceGenerator(name = "facilityLocationSeq", initialValue = 374, allocationSize = 1)
@GeneratedValue (strategy = GenerationType.SEQUENCE, generator = "facilityLocationSeq")
@Column(updatable= false, nullable = false, unique = true)
private Long locationIdPk;

@OneToOne (fetch = FetchType.EAGER)
@JoinColumn (name="facilityIdFk", referencedColumnName ="generalIdPk", nullable = false)
@JsonIgnore
private FacilityGeneral facilityGeneral;

private Double latitudeDegrees;
private Double latitudeMinutes;
private Double latitudeSeconds;
private Double longitudeDegrees;
private Double longitudeMinutes;
private Double longitudeSeconds;
private Double northing;
private Double easting;
private Double xCoordinate;
private Double yCoordinate;
private String descriptiveDirections;
private String county;
private String healthDepartment;
private String healthDepartContact;
private String facilityAddressStreet;
private String facilityAddressCity;
private Integer facilityZipFiveDigit;
private Integer facilityZipFourDigit;
private Integer townshipNumber;
private String townshipDirection;
private Integer rangeNumber;
private String rangeDirection;
private String section;
private String quarterSection;
private String qtrQtrSection;
private String baseline;

@JsonFormat(pattern = "MM/dd/yyyy")
private LocalDate created_on;

private Integer politicalDistrictHouse;
private Integer politicalDistrictSenate;
private String comments;
private Double latitudeDecimalDegrees;
private Double longitudeDecimalDegrees;

来自FacilityLocation查询的结果对象不包含我需要的facilityIdFk字段:

 {
    "locationIdPk": 53,
    "latitudeDegrees": 38,
    "latitudeMinutes": 10,
    "latitudeSeconds": 10.16,
    "longitudeDegrees": 100,
    "longitudeMinutes": 10,
    "longitudeSeconds": 10.10,
    "northing": 0.000,
    "easting": 0.00,
    "xCoordinate": 000.0000,
    "yCoordinate": 4241085.372,
    "descriptiveDirections": "Approximately three miles northwest of Beaver and one mile east of Interstate 15",
    "county": "Beaver",
    "healthDepartment": "Public Health Department",
    "healthDepartContact": null,
    "facilityAddressStreet": null,
    "facilityAddressCity": "Beaver",
    "facilityZipFiveDigit": 0,
    "facilityZipFourDigit": 0,
    "townshipNumber": 29,
    "townshipDirection": "S",
    "rangeNumber": 7,
    "rangeDirection": "W",
    "section": "8",
    "quarterSection": "NW",
    "qtrQtrSection": "NE",
    "baseline": "SLBM",
    "created_on": "07/03/2006",
    "politicalDistrictHouse": null,
    "politicalDistrictSenate": 28,
    "comments": "Facility is located in the NE of the NW, the SE of the NW, and the NE of the NE quarter of section 8",
    "latitudeDecimalDegrees": 0.000,
    "longitudeDecimalDegrees": 0.000,
    "modified_on": null
},

0 个答案:

没有答案