Hibernate GeneratedValue 不能正常工作

Hibernate GeneratedValue does not works properly

晚安,我正在尝试通过 Hibernate 的 IncrementGenerator 策略使用增量实现。

但是,在查询中它没有在 SQL 中添加 SCHEMA:

select max(nr_prop) from prop_tran

预计:

select max(nr_prop) from db2ozt.prop_tran

class如下:

@Entity
@Table(name = "PROP_TRAN", schema = "DB2OZT")
public class RuralProperty implements Serializable {
  private static final long serialVersionUID = 1L;

  @Id
  @Column(name = "NR_PROP")
  @GenericGenerator(name="id_for_prop", strategy="org.hibernate.id.IncrementGenerator")
  @GeneratedValue(generator="id_for_prop")
  private Short nmrProp;

  ...
}

版本:5.4.32.Final

观察。 我无法在数据库中添加序列或自动递增。有开发限制。

提前致谢!

您必须将用于序列的模式作为参数传递给 @GenericGenerator:

@GenericGenerator(
  name = "id_for_prop",
  strategy = "org.hibernate.id.IncrementGenerator",
  parameters = {
    @Parameter(name = "schema", value = "DB2OZT")
  }
)