Hi,
I would like do have some static fields in my entity which will populated with some domain objects. For example fields for default category - when new entity is created it will automatically assign this default category to category field.
class Product {
public static Category defaultCategory1 ;
@Column
Category category ;
public Product(boolean isNew) {
if(isNew) {
category = defaultCategory1 ;
}
}
}
This is oversimplified example. In reality I can have complicated logic for many fields and and may be some related entities will be generated.
Right now I, off cause, can assign the category for the new entity from outside for each new entity or do one assignment for the static field.
So, my code will alway look like this:
Product.initializeDefaults(entityManager) ; //or whatever method I choose
// to initialize the static fields
Product p = new Product(true) ;
Does anyone have any suggestions about this logic? Can Hibernate automate any of this or it must be manual for each class?
|