[PersistenceException: Error getting sequence next

2019-02-23 01:21发布

i am getting this error while trying to save data into model in db.

@Entity
public class User extends Model {
   @Required
   public String name; 
   @Email
   public String email; 
   @Required @MaxLength(value=10)
   public String username;
   @Required @MinLength(value=4)
   public String password;
   @Id 
   public int id;
}

this is my Class.

this is the error while i am trying to save the model into db.

enter image description here

i will appreciate any effort for help! many thanks.

EDIT: table structure is here enter image description here

3条回答
萌系小妹纸
2楼-- · 2019-02-23 01:40

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.

查看更多
Explosion°爆炸
3楼-- · 2019-02-23 01:52

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.

查看更多
相关推荐>>
4楼-- · 2019-02-23 01:56

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.

查看更多
登录 后发表回答