简体   繁体   中英

auto increment on postgresql going too high after playframework exception

Good afternoon,

I have a method that adds a column to a postgresql table(created by hibernate) that have an auto increment field, and its working fine.

My problem starts after it encounter an exception, the column that was going to be added isnt(thats okay) but the next field added have the auto generated id set to 32678, the next one 65536 and so on.

It is not something specific for a exception, it happens after any exception on the system.

Here is where the fields are declared:

@MappedSuperclass
public class BaseModel extends GenericModel {

@Id
@GeneratedValue(strategy = GenerationType.TABLE)
public Long id;

public Long getId() {
return id;
}

@Override
public Object _key() {
return getId();
}

}

Thanks in advance.

The TABLE strategy doesn't consist in using an auto_increment field in the table. It consists in using an external table acting as a set of sequences, using a HI/LO algorithm. The jump is a consequence of jumping to the next HI value.

I would advise using sequences with PostgreSQL. They're the most natural choice, IMHO.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM