Issue
Good night, I'm trying to use the increment implementation through Hibernate's IncrementGenerator strategy.
However, in the query it does not add the SCHEMA in SQL:
select max(nr_prop) from prop_tran
Expected to be:
select max(nr_prop) from db2ozt.prop_tran
The class is as follows:
@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;
...
}
Version: 5.4.32.Final
Obs. I can't add sequence or auto increment in the database. There are development restrictions.
Thanks in advance!
Solution
You have to pass the schema to use for the sequence as parameter to the @GenericGenerator
:
@GenericGenerator(
name = "id_for_prop",
strategy = "org.hibernate.id.IncrementGenerator",
parameters = {
@Parameter(name = "schema", value = "DB2OZT")
}
)
Answered By - Christian Beikov