AutoIncrement failing
I have a table named collections in SQLite database with id as autoincrement and I’m using Spring Boot + Hibernate to connect to SQLite database. I’ve found that insert to collections table is failing with following error
What could be the reason for this?
Error Message
org.springframework.dao.DataIntegrityViolationException: A different object with the same identifier value
was already associated with the session : [com.product.cache.engine.entity.Collection#1624314]; nested
exception is javax.persistence.EntityExistsException: A different object with the same identifier value was
already associated with the session : [com.product.cache.engine.entity.Collection#1624314]
Entity class
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
@ToString(doNotUseGetters = true)
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode
@Builder
@Entity
@Table(name = TableConstants.COLLECTIONS)
public class Collection {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = TableConstants.ENTITY_ID)
private Long id;
@Column(name = TableConstants.PRODUCT_ID)
@JsonProperty(value = TableConstants.PRODUCT_ID)
private Long productId;
@Column(name = TableConstants.COLLECTION_ID)
@JsonProperty(value = TableConstants.COLLECTION_ID)
private Long collectionId;
@Column(name = TableConstants.BOT_REF)
@JsonProperty(value = TableConstants.BOT_REF)
private Integer botRef;
@Column(name = TableConstants.SHOP_DOMAIN)
@JsonProperty(value = TableConstants.SHOP_DOMAIN)
private String shopDomain;
@Column(name = TableConstants.DESCRIPTION)
@JsonProperty(value = TableConstants.DESCRIPTION)
private String description;
@Column(name = TableConstants.HANDLE)
@JsonProperty(value = TableConstants.HANDLE)
private String handle;
@Column(name = TableConstants.TITLE)
@JsonProperty(value = TableConstants.TITLE)
private String title;
@Column(name = TableConstants.IMAGE_URL)
@JsonProperty(value = TableConstants.IMAGE_URL)
private String imageUrl;
@Column(name = TableConstants.UPDATED_AT)
@JsonProperty(value = TableConstants.UPDATED_AT)
@JsonFormat(shape= JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm:ss")
private Timestamp updatedAt;
}
gwenn SQLite-dialect & xerial jdbc-driver versions
implementation("org.xerial:sqlite-jdbc:3.36.0.3")
implementation("com.github.gwenn:sqlite-dialect:0.1.0")
Could you please try the last released version 0.1.2. Or this unreleased patch related to Identity:
use_get_generated_keys must be set to
falseto activate RETURNING clause
You should also try to activate sqlite3_trace with your sqlite-jdbc driver or at least hibernate.show_sql.
Could you please try the last released version 0.1.2. Or this unreleased patch related to Identity:
use_get_generated_keys must be set to
falseto activate RETURNING clauseYou should also try to activate
sqlite3_tracewith yoursqlite-jdbcdriver or at leasthibernate.show_sql.
Thank you for the suggestion. Will try to upgrade the version. Sad part is it is not replicable on our test environment. So will have to keep this issue open till we directly test on our production environment 😃
And in case you didn't know: https://hibernate.atlassian.net/browse/HHH-10668 So if you use hibernate >= 6, you should use the community dialect instead...
And in case you didn't know: https://hibernate.atlassian.net/browse/HHH-10668 So if you use hibernate >= 6, you should use the community dialect instead...
We are using hibernate 5.4.25.Final