在兴奋之下:
Finest: persist() operation called on: MyUser{ID=null,email=a@e.it,password=test,firstname=test,lastname=test,company=Test}. Finest: Execute query ValueReadquery(sql="select nextval('mom_seq_ID')") Finest: Connection acquired from connection pool [read]. Finest: reconnecting to external connection pool Fine: select nextval(mom_seq_ID) Finest: Connection released to connection pool [read]. Warning: Local Exception Stack: Exception [Eclipselink-7027] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.ValIDationException Exception Description: The sequence named [mom_seq_ID] is setup incorrectly. Its increment does not match its pre-allocation size.at org.eclipse.persistence.exceptions.ValIDationException.sequenceSetupIncorrectly(ValIDationException.java:1604)at org.eclipse.persistence.sequencing.StandardSequence.createVector(StandardSequence.java:96) ...
Postgres上的序列:
CREATE SEQUENCE my_seq_ID INCREMENT 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 27 CACHE 1;ALTER table my_seq_ID OWNER TO postgres;COMMENT ON SEQUENCE my_seq_ID IS 'Sequence for autoincrement ID on MyClass';
以及我的实体的摘录:
@Entity@table(name = "myuser")@XmlRootElementpublic class MyUser implements Serializable {private static final long serialVersionUID = 1L;@ID@SequenceGenerator(name="MYSEQ",sequencename="my_seq_ID")@GeneratedValue(strategy = GenerationType.SEQUENCE,generator="MYSEQ")@Basic(optional = false)@Column(name = "ID")private Integer ID;
任何人都可以解释什么是错的?
谢谢
我解决了我的问题,但我不知道为什么!我看到allocationSize()的默认值是50:
package javax.persistence;@Target(value = {ElementType.TYPE,ElementType.METHOD,ElementType.FIELD})@Retention(value = RetentionPolicy.RUNTIME)public @interface SequenceGenerator { public String name(); public String sequencename() default ""; public String catalog() default ""; public String schema() default ""; public int initialValue() default 1; public int allocationSize() default 50;}
我已将我的Postgres序列increment_by值从1更新为50,现在它可以工作了!
解决方法 将INCREMENT的值从1改为50到我的Postgres序列解决了这个问题.正如@unwichtich所建议的那样,通过@SequenceGenerator注释指定allocationSize = 50属性是个好主意. 总结以上是内存溢出为你收集整理的postgresql – JPA和Postgres序列预分配大小设置不正确全部内容,希望文章能够帮你解决postgresql – JPA和Postgres序列预分配大小设置不正确所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)