Appearance
Relationships
Squizy supports standard JPA relationship annotations and automatically generates the appropriate UI components for managing related entities.
UI Rendering Summary
The UI component used for a relationship depends on the relationship type and ownership (cascade configuration):
| Relationship | Owned (cascade ALL) | Reference (no cascade) |
|---|---|---|
@ManyToOne | — | Dropdown / select |
@OneToOne | Inline form (embedded) | Dropdown / select |
@OneToMany | Inline table | — |
@ManyToMany | — | Multi-select (chips) |
@ElementCollection | Inline list | — |
Owned relationships (cascade = CascadeType.ALL, orphanRemoval = true) allow creating and editing child records directly from the parent form. Reference relationships link to independently managed entities via selection components.
Supported Relationships
@ManyToOne
Renders as a dropdown/select in the UI:
java
@Entity
@SquizyEntity
public class Product {
@ManyToOne(optional = false)
@NotNull
private Category category;
}@OneToOne
Renders as a dropdown or inline form depending on cascade configuration:
java
@Entity
@SquizyEntity
public class Order {
@OneToOne(optional = false, cascade = CascadeType.ALL, orphanRemoval = true)
@NotNull
private Address address;
}@OneToMany
Renders as a multi-select or inline table:
java
@Entity
@SquizyEntity
public class Order {
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
@NotEmpty
private List<OrderLine> products;
}@ManyToMany
Renders as a multi-select component:
java
@Entity
@SquizyEntity
public class City {
@ManyToMany(fetch = FetchType.EAGER)
private Set<City> closeCities;
}@ElementCollection
Supported for both simple types and enums:
java
@ElementCollection
private List<String> aliases;
@ElementCollection(targetClass = Badge.class)
@CollectionTable
@Enumerated(EnumType.STRING)
private List<Badge> badges;Cascade Operations
Owned Entities (cascade all)
When a child entity's lifecycle is fully managed by the parent:
java
@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true)
private Address address;
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
private List<OrderLine> products;With orphanRemoval = true, removing a child from the collection deletes the orphaned record.
Reference Entities (no cascade)
When a child entity has its own independent lifecycle:
java
@ManyToOne(optional = false)
@NotNull
private Category category;Bidirectional Relationships
For bidirectional relationships, use mappedBy on the non-owning side:
java
@Entity
@SquizyEntity
public class Owner {
@OneToMany(cascade = CascadeType.ALL, mappedBy = "owner", orphanRemoval = true)
private List<Book> books;
}
@Entity
@SquizyEntity
public class Book {
@ManyToOne
@JsonBackReference
private Owner owner;
}Use @JsonManagedReference / @JsonBackReference or @JsonIgnoreProperties to avoid circular serialization issues.