Java 基于外键的Hibernate非主键自动递增
我正在处理一个包含整数列和外键的表。这个整数必须是递增的,但当外键更改时,它必须在1中重新开始 例如:Java 基于外键的Hibernate非主键自动递增,java,oracle,hibernate,foreign-keys,primary-key,Java,Oracle,Hibernate,Foreign Keys,Primary Key,我正在处理一个包含整数列和外键的表。这个整数必须是递增的,但当外键更改时,它必须在1中重新开始 例如: Foreign 1, int col : 1 , 2 , 3... Foreign 2, int col: 1 ,2 , 3, 4, 5 ... Foreign 3, int col: 1, 2 这是我到目前为止的映射:(当然这不起作用) 有没有办法用Hibernate(Oracle DB)做到这一点 在hibernate中有很多方法可以做到这一点,请先给我们表的create语句。创建表
Foreign 1, int col : 1 , 2 , 3...
Foreign 2, int col: 1 ,2 , 3, 4, 5 ...
Foreign 3, int col: 1, 2
这是我到目前为止的映射:(当然这不起作用)
有没有办法用Hibernate(Oracle DB)做到这一点 在hibernate中有很多方法可以做到这一点,请先给我们表的create语句。创建表文档(ID INTEGER NOT NULL,TYPE INTEGER NOT NULL,IDX INTEGER,DOC VARCHAR(255));创建表文档类型(ID INTEGER不为NULL,名称VARCHAR(255))很棒。您是否使用Oracle 12c或更高版本?我目前正在使用Oracle 12:)
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;
}