I am using hibernate annotation @GenerateType to generate the value for the non-primary key. Here I need to pass some values(as parameters) to generator class. I saw we can do it using Configurable. But problem is we can only use them for primary keys(@Id), whereas my one is non-primary. Can any one suggest me the right approach.
Code:
@Entity
public class Student{
@GeneratorType(type = IdGenerator.class,when= GenerationTime.INSERT)
private Integer deptId;
}
public class IdGenerator implements ValueGenerator<Integer>{
@Override
public Integer generateValue(Session session, Object owner) {
//Need to return value based on parameter** which changes dynamically.
}
}