Hibernate does not allow for overlapping foreign keys https://hibernate.atlassian.net/browse/HHH-6221.
Because of this issue it is harder to generate database schema where foreign keys shares tenant id column with primary key and other foreign keys.
For below example we have two tables:
The user_info_nonforeignkeyconstraint table can have multiple references to posts table.
create table posts_nonforeignkeyconstraint (
key int8 not null,
tenant_id varchar(255) not null,
text text,
user_id varchar(255),
primary key (key, tenant_id)
)
To map these tables into java model and having issue "Mixing insertable and non insertable columns in a property is not allowed" we need to use JoinColumnsOrFormulas annotation.
@Embeddable
public class StringPrimaryKey implements Serializable {
private String stringKey;
private String tenant;
//Setters, Getters, equals and hashCode
The problem with this approach is that Hibernate does not generate foreign key in posts_nonforeignkeyconstraint to user_info_nonforeignkeyconstraint table. Developer needs to for test purpose add this statement in import.sql file.
The goal is to add feature that will lookup for such *annotation combination (activated by a property) or with specified annotation for property and generate foreign key based on tenant column and column that reference to other table.
IgnoreForeignKeyCreation // In case when the foreign key is by default created
ForeignKeyCreation
table = table name (optional) // It would be used in the case when implementation would create a foreign key for the wrong table.
schema = schema name (optional)
tenantColumnReference = name of tenant column for reference table (optional)
columnsReference = array of objects JoinColumn()
Hibernate does not allow for overlapping foreign keys https://hibernate.atlassian.net/browse/HHH-6221. Because of this issue it is harder to generate database schema where foreign keys shares tenant id column with primary key and other foreign keys. For below example we have two tables: The user_info_nonforeignkeyconstraint table can have multiple references to posts table.
To map these tables into java model and having issue "Mixing insertable and non insertable columns in a property is not allowed" we need to use JoinColumnsOrFormulas annotation.
The problem with this approach is that Hibernate does not generate foreign key in posts_nonforeignkeyconstraint to user_info_nonforeignkeyconstraint table. Developer needs to for test purpose add this statement in import.sql file.
The goal is to add feature that will lookup for such *annotation combination (activated by a property) or with specified annotation for property and generate foreign key based on tenant column and column that reference to other table.
Blocked by: https://github.com/starnowski/posmulten/issues/252