Hibernate allocateSize 忽略“allocationSize”
如何整理hibernate和数据库序列生成?
我的实体:
package kz.open.sankaz.model;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.security.core.GrantedAuthority;
import javax.persistence.*;
@Entity
@Table(name = "SEC_ROLE")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class SecRole extends AbstractEntity implements GrantedAuthority {
@Id
@GeneratedValue(generator = "SEC_ROLE_SEQ", strategy = GenerationType.SEQUENCE)
@SequenceGenerator(allocationSize = 1, sequenceName = "SEC_ROLE_ID_SEQ", name = "SEC_ROLE_ID")
private Long id;
@Column(name = "NAME", nullable = false, unique = true)
private String name;
@Override
public String getAuthority() {
return getName();
}
}
我写道“allocationSize”是1。但是Hibernate生成错误的查询:
Hibernate: create sequence public.sec_role_seq start 1 increment 50
它不仅在插入新数据时产生问题,而且在运行数据库迁移查询时也会产生问题。比如我写了下一行:
create sequence public.sec_role_seq start 1 increment 1;
和Hibernate冲突了:
The increment size of the [SEC_ROLE_SEQ] sequence is set to [50] in the entity mapping while the associated database sequence increment size is [1]
怎么解决?请帮忙!
How to put in order hibernate and database sequence generation?
My entity:
package kz.open.sankaz.model;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.security.core.GrantedAuthority;
import javax.persistence.*;
@Entity
@Table(name = "SEC_ROLE")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class SecRole extends AbstractEntity implements GrantedAuthority {
@Id
@GeneratedValue(generator = "SEC_ROLE_SEQ", strategy = GenerationType.SEQUENCE)
@SequenceGenerator(allocationSize = 1, sequenceName = "SEC_ROLE_ID_SEQ", name = "SEC_ROLE_ID")
private Long id;
@Column(name = "NAME", nullable = false, unique = true)
private String name;
@Override
public String getAuthority() {
return getName();
}
}
I wrote that "allocationSize" is 1. But Hibernate generates wrong query:
Hibernate: create sequence public.sec_role_seq start 1 increment 50
It makes a problem not only while you are inserting a new data, it also makes problem when you are running database migration queries. For example, I wrote the next line:
create sequence public.sec_role_seq start 1 increment 1;
and Hibernate conflicts with it:
The increment size of the [SEC_ROLE_SEQ] sequence is set to [50] in the entity mapping while the associated database sequence increment size is [1]
How to solve it? Please, help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过以下方式解决了更改生成器的问题:
I solved it changing generator in the following way: