简体   繁体   中英

[PersistenceException: Error getting sequence nextval]

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.

在此输入图像描述

i will appreciate any effort for help! many thanks.

EDIT: table structure is here 在此输入图像描述

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.

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