Hibernate does not create foreign key in tables in bidirectional one-to-one relation

350 views Asked by At

These are my classes:

@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;

}

When i start the application to create table, in create table but does not create foreign keys in app_customers and app_address.

1

There are 1 answers

0
Peter Šály On