我一直在阅读很多关于@JoinColumn的内容,但我仍然不了解它背后的想法.
病人表
CREATE TABLE patient (
patient_id BIGINT NOT NULL,
first_name VARCHAR(255) NOT NULL,
last_name VARCHAR(255) NOT NULL,
PRIMARY KEY(patient_id));
Run Code Online (Sandbox Code Playgroud)
车辆表
CREATE TABLE vehicles (
patient_id BIGINT NOT NULL,
vehicle_id BIGINT NOT NULL,
vehicle_manufacturer VARCHAR(255),
PRIMARY KEY (vehicle_id),
CONSTRAINT patienthasmanyvehicle FOREIGN KEY(patient_id) REFERENCES patient(patient_id));
Run Code Online (Sandbox Code Playgroud)
患者类
@OneToMany(mappedBy = "patient")
private Collection<Vehicle> patientVehicles = new ArrayList<Vehicle>();
Run Code Online (Sandbox Code Playgroud)
车辆类
@ManyToOne
@JoinColumn(name="patient_id")
private Patient patient;
Run Code Online (Sandbox Code Playgroud)
我对车辆类如何部分感到困惑,之间的关系是什么
Vehicle Class ---- Entity
@JoinColumn(name="patient_id") ---- annotation
private Patient patient ----field
Run Code Online (Sandbox Code Playgroud)
是吗?该车辆实体有一个外键到患者实体命名patient_id …
我有一个工作代码,其中我的改造客户端可以从 api 检索对象(国家/地区)列表。问题是,如果我用来检索所有国家/地区,则 api 使用的参数会返回一个 ARRAY,那么当我想要查询单个国家/地区时,它会返回单个 OBJECT。结果显示以下异常。
java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 4 column 17 path $.RestResponse.result
Run Code Online (Sandbox Code Playgroud)
顺便说一句,我正在使用Retrofit 2。
我尝试了此线程中已接受的答案 How to handleparameters that can be an ARRAY or OBJECT in Retrofit on Android?
但仍然行不通。这是我的实现。
应用程序编程接口
http://services.groupkt.com/country/get/all
http://services.groupkt.com/country/get/iso2code/{alpha2_code}
Run Code Online (Sandbox Code Playgroud)
API接口
public interface ApiInterface {
@GET("country/get/all")
Call<Example> getCountry();
@GET("country/get/iso2code/{alpha2_code}")
Call<Example> searchCountryByIso2Code(@Path("alpha2_code") String alpha2Code);
@GET("country/get/iso3code/{alpha3_code}")
Call<Example> searchCountryByIso3Code(@Path("alpha3_code") String alpha3Code);
@GET("country/search?text={text to search}")
Call<Example> searchCountry(@Path("text to search") String searchText);
}
Run Code Online (Sandbox Code Playgroud)
国家/地区类型适配器
public class CountryTypeAdapter extends TypeAdapter<RestResponse> {
private Gson mGson = …Run Code Online (Sandbox Code Playgroud) 我有这些实体;
Person.class
@Entity
@Table(name = "person")
@Inheritance(strategy=InheritanceType.JOINED)
public abstract class Person implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
@Column(name = "person_id")
private long personID;
Run Code Online (Sandbox Code Playgroud)
StudentBean.class
@Entity
@Table(name = "student_information")
public class StudentBean extends Person {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private long studentID;
Run Code Online (Sandbox Code Playgroud)
我的目标是将学生记录与Person类和StudentBean类中的详细信息一起保存在1个表中,但是我遇到了这些异常
org.hibernate.mapping.JoinedSubclass无法强制转换为org.hibernate.mapping.RootClass
在我的研究中我偶然发现了这个线程[Spring 3.1 Hibernate 4的继承异常无法转换为org.hibernate.mapping.RootClass
基于此,异常的原因是由于Parent和Child类中的@Id.但是如果我在我的任何一个类中删除了@Id,它将不允许我保存该对象,因为我没有我的实体的标识符.
我想要一个人员ID来识别学校外的人和学生证来识别学校里面的人,这可能吗?如果没有,我怎么能删除Person类的PK,但我仍然可以扩展它并将其保存到另一个表中.
最后,实现这个设计的最佳方式是什么,Person可以扩展为Student Class,Teacher Class,SchoolPrincipal Class