I'm working with a table that has an integer column and a foreign key. This integer has to be incremental, but it has to start again in 1 when the foreign key is changed.
Example:
Foreign 1, int col : 1 , 2 , 3...
Foreign 2, int col: 1 ,2 , 3, 4, 5 ...
Foreign 3, int col: 1, 2
This is my mapping so far: (Of course this doesn't does the trick)
public class Documento implements ModelEntity{
private static final long serialVersionUID = 11233L;
/*PK*/
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
/*FK*/
@Man yToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "type_id")
@Cascade({})
private Type type;
/* This is the value that has to be AUTO-INCREMENT BASED ON FOREIGN_ID */
@Basic
private Integer idx;
}
Is there a way to do this with Hibernate (Oracle DB) ?