References to another tables - Zalizyaka-Ney/handy.storage GitHub Wiki
The framework can simplify the routine with referrencing to data in another table - just declare a field with Reference annotation. For example:
public class Author extends UniqueObject {
@Column
private String name;
}
public class Book extends UniqueObject {
@Column
private String title;
@Column
@Reference
private Author author;
}
The framework automatically finds an appropriate column in a referrenced table, declares a foreign key column and handles futher routine when you insert in and read from the table.
But the framework doesn’t automatically insert referenced objects into a referenced table during an insertion in a referencing table, those objects must be inserted before that insertion (in the example - you should insert an author object before inserting a book).
The referrenced table must have a primary key or unique column (+ autoincrement or not null).