Hibernate不会在双向一对一关系中的表中创建外键



这些是我的类:

@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public abstract class BaseEntity<T> implements Serializable {
    @Id
    @Column(name = "id", unique = true, nullable = false)
    @GeneratedValue(strategy = GenerationType.AUTO)
    private T id;
}
@Entity
@Table(name = "core_users")
@Inheritance(strategy = InheritanceType.JOINED)
public class User extends BaseEntity<Long> implements UserDetails {
}
@Entity
@Table(name = "app_customers")
public class BaseCustomer extends User {
    @OneToOne(mappedBy = "owner", cascade = CascadeType.ALL)
    private Address address;
}
@Entity
@Table(name = "app_address")
public class Address extends BaseEntity<Long> {
    @Id
    @Column(name = "id", unique = true, nullable = false)
    @GeneratedValue(generator = "gen")
    @GenericGenerator(name = "gen", strategy = "foreign", parameters = @Parameter(name = "property", value = "owner"))
    private Long id;
    @OneToOne
    @PrimaryKeyJoinColumn
    private BaseCustomer owner;
}

当我启动应用程序以创建表格,在创建表中,但不会在app_customersapp_address中创建外键。

joneid继承不使用外键。阅读更多:https://en.wikibooks.org/wiki/java_persistence/inheritance#joined.2c_multiple_table_inheritance

相关内容

  • 没有找到相关文章

最新更新