[PersistenceException: Error getting sequence nextval]

不想你离开。 提交于 2019-12-01 18:18:50

I think with ebean you have to physically name and annotate your id. You may also have to tell it the name of the backing sequencer as well (I dont remember). This shows how to do it.

This worked for me:

@Entity
@Table(name = "table", schema = "schema")
public class Bean extends Model{

   @Id
   @Column(name = "idcolumn")
   @SequenceGenerator(name="gen", sequenceName="schema.table_idcolumn_seq",allocationSize=1) 
   @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "gen")
   private int id;
}

When using the SequenceGenerator, please mind this bug in Hibernate: https://hibernate.atlassian.net/browse/HHH-7232

It forces you to write the schema directly into the sequenceName instead of using the schema field in the SequenceGenerator annotation.

This worked for me on class annotation:

@SequenceGenerator(name = "SEQUENCE_NAME", sequenceName = "PST_BUSINESS.S_BUSINESS_DOMAIN")
@Entity
@Table(name = "TB_BUSINESS_DOMAIN", schema = "PST_BUSINESS")
public class PstBusinessDomain extends PstAbstractBaseMappedEntity {

As Leo said, this strategy works for annotation in the field and also in the class.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!