我有简单的实体类:
@Entity @Table(name = "NH_ENTITIES") @Getter @Setter @ToString public class Entita { /** * Primary key. */ @Id @Column(name = "PK", nullable = false, length = NHConstants.DB_STANDARD_LENGTH) @GeneratedValue(strategy = GenerationType.AUTO, generator = "nh_entities_gen") @SequenceGenerator(name = "nh_entities_gen", sequenceName = "NH_ENTITIES_SEQ", initialValue = 1, allocationSize = 1) private int pk; /** * Entity name. */ @NotEmpty(message = "Entita je povinná") @Size(max = NHConstants.DB_MAX_LENGTH, message = "Maximální počet znaků: " + NHConstants.DB_MAX_LENGTH) @Column(name = "ENTITY", unique = true, nullable = false, length = NHConstants.DB_MAX_LENGTH) private String entity = ""; /** * For Hibernate only. */ public Entita() { } }和我的服务方法:
@Override @Transactional(readOnly = false, propagation = Propagation.REQUIRED) public void saveEntity(Entita entity) { log.debug("Start transaction saveEntity"); this.entityRepo.save(entity); log.debug("Transaction saveEntity finished"); }当我通过某个sql客户端手动向这个实体插入行/行时,以编程方式执行saveEntity即时获取错误无法执行语句; SQL [不适用]; 约束[C ## NH.SYS_C0013920]; 嵌套异常是org.hibernate.exception.ConstraintViolationException:无法执行语句
这个错误我只得到一次....这取决于我手动插入多少行....
除了在保存之前执行findlast之外,还有另一种方法可以解决这个问题吗?
谢谢你的建议。
i have simple entity class:
@Entity @Table(name = "NH_ENTITIES") @Getter @Setter @ToString public class Entita { /** * Primary key. */ @Id @Column(name = "PK", nullable = false, length = NHConstants.DB_STANDARD_LENGTH) @GeneratedValue(strategy = GenerationType.AUTO, generator = "nh_entities_gen") @SequenceGenerator(name = "nh_entities_gen", sequenceName = "NH_ENTITIES_SEQ", initialValue = 1, allocationSize = 1) private int pk; /** * Entity name. */ @NotEmpty(message = "Entita je povinná") @Size(max = NHConstants.DB_MAX_LENGTH, message = "Maximální počet znaků: " + NHConstants.DB_MAX_LENGTH) @Column(name = "ENTITY", unique = true, nullable = false, length = NHConstants.DB_MAX_LENGTH) private String entity = ""; /** * For Hibernate only. */ public Entita() { } }and my service method:
@Override @Transactional(readOnly = false, propagation = Propagation.REQUIRED) public void saveEntity(Entita entity) { log.debug("Start transaction saveEntity"); this.entityRepo.save(entity); log.debug("Transaction saveEntity finished"); }when i manually insert row/rows to this entity by some sql client and afterthat execute saveEntity programatically im getting the error could not execute statement; SQL [n/a]; constraint [C##NH.SYS_C0013920]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement
This error im getting just once....it depends how many rows i inserted before manually....
Is there another way how to handle this issue except execute findlast before save?
Thank you for your suggestion.
最满意答案
我解决了我的问题。 我在DB中顺序插入了数字。为此目的使用序列是必要的。
I resolved my issue. i inserted exactly the numbers sequencially in DB It is neccessary to use the sequence for this purpose.
更多推荐
saveEntity,entity,Entita,NHConstants,execute,电脑培训,计算机培训,IT培训"/> <
发布评论