Hi @remmeier I want to remove the foreign key constraint but to keep the relation between objects but without having a constraint
so If we have a parent object which has a list of childs
I want to easily link a non existent parent to a child object
this is can be done using jpa only in spring boot using this annotation @org.hibernate.annotations.ForeignKey(name = "none") but with crnk it returns like this when doing a post
"errors": [
{
"status": "404",
"code": "NOT_FOUND",
"detail": "type=parent, ids=[2972b858-8f77-4462-89bb-7a406e248f46]",
"source": {
"pointer": ""
},
"meta": {
"type": "NOT_FOUND",
"resourceType": "child"
}
}
]
}
Parent class
@Data
@JsonApiResource(type = "parent", resourcePath = "parents")
@Entity
@Table(name = "parents")
public class Parent {
@Id
@JsonApiId
private UUID id;
private String name;
@JsonApiRelation(opposite = "parent",
lookUp = LookupIncludeBehavior.AUTOMATICALLY_WHEN_NULL,
repositoryBehavior = RelationshipRepositoryBehavior.FORWARD_OPPOSITE)
@OneToMany(mappedBy = "parent")
@org.hibernate.annotations.ForeignKey(name = "none")
private List<Child> childs;
}
Child Class
@Data
@JsonApiResource(type = "child", resourcePath = "childs")
@Entity
@Table(name = "childs")
public class Child {
@Id
@JsonApiId
@GeneratedValue(generator = "UUID")
@GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator")
@Column(name = "id", updatable = false, nullable = false)
private UUID id;
@JsonApiRelationId
@Column(name = "parent_id")
private UUID parentId;
private String type;
@JsonApiRelation(idField = "parentId", opposite = "childs",
lookUp = LookupIncludeBehavior.AUTOMATICALLY_WHEN_NULL,
repositoryBehavior = RelationshipRepositoryBehavior.FORWARD_OWNER,
serialize = SerializeType.EAGER)
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "parent_id", insertable = false, updatable = false)
@org.hibernate.annotations.ForeignKey(name = "none")
private Parent parent;
public void setParentId(UUID parentId) {
this.parentId = parentId;
this.parent = null;
}
public void setParent(Parent parent) {
this.parent = parent;
this.parentId = parent != null ? parent.getId() : null;
}}
this creates a hashCode method for all properties and this triggers many lazy load queries when it creates a TupleElement at a certain point:
TupleElement(Object[] data) {
this.data = data;
this.hashCode = Arrays.hashCode(data);
}