我需要在mysql表中一次保存两个实体。以下是两个实体 一个是UserEntity,另一个是UserDetailsEntity。我想在UserDetails表中插入UserId列作为外键。但是UserDd没有插入UserDetails表中。在这个Plz中帮助我。
UserEntity.java
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "UserId")
private int id;
@Column(name = "UserLogin", length = 15, unique = true)
private long phNumber;
@Column(name = "Password", length = 100)
private String password;
@Column(name = "UserType", length = 20)
private String userType;
@Column(name = "PromoCode", length = 20)
private String promoCode;
@Column(name = "FirstName", length = 30)
private String firstName;
@Column(name = "LastName", length = 30)
private String lastName;
@Column(name = "RoleId")
private int roleId;
@Column(name = "isActive")
private int isActive;
@Column(name = "isTestUser")
private int isTestUser;
@Column(name = "FcmToken", length = 100)
private String fcmToken;
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "UserId", unique = true,insertable = true, updatable = true)
//@ForeignKey(name = "UserId")
private UserDetailsEntity userDetailsEntity;
// getters and setters
UserDetailsEntity.java
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "UserDetailsId")
private int id;
@Column(name="UserId", unique=true, nullable=false)
@GeneratedValue(generator="gen")
@GenericGenerator(name="gen", strategy="foreign", parameters={@Parameter(name="property", value="uid")})
private int userId;
@Column(name ="AadhaarCardNumber" ,length = 12)
private long aadhaarNumber;
@Column(name="", length = 50)
private String emailId;
@Column(name="Address1" , length = 30)
private String address1;
@Column(name="Address2", length = 30)
private String address2;
@Column(name="CityId", length = 10)
private int cityId;
@Column(name="StateId", length = 10)
private int stateId;
@Column(name="CountryId", length = 10)
private int countryId;
@Column(name="Latitude", length = 60)
private String lat;
@Column(name="Longitude", length = 60)
private String lng;
@Column(name="MobileNumber1", length = 15)
private long mobileNumber1;
@Column(name="MobileNumber2", length = 15)
private long mobileNumber2;
@Column(name="DOB", length = 15)
private Date dob;
@OneToOne
private UserEntity userEntity;
// getter and setters here
答案 0 :(得分:0)
我自己找到了解决方案。让我更新。只需在parent表中提及注释OneToOne(这里是Users)。和UserDetails的Id的子表将存储在父表中。 <ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:layout_marginTop="50dp"
app:srcCompat="@drawable/login_bottom_coloured_line" />
我的要求已经完成,与UserDetailsEntity无关。