Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AutoIncrement failing #36

Open
29swastik opened this issue Nov 24, 2022 · 4 comments
Open

AutoIncrement failing #36

29swastik opened this issue Nov 24, 2022 · 4 comments

Comments

@29swastik
Copy link

29swastik commented Nov 24, 2022

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")
@gwenn
Copy link
Owner

gwenn commented Nov 24, 2022

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 false to activate RETURNING clause

You should also try to activate sqlite3_trace with your sqlite-jdbc driver or at least hibernate.show_sql.

@29swastik
Copy link
Author

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 false to activate RETURNING clause

You should also try to activate sqlite3_trace with your sqlite-jdbc driver or at least hibernate.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 😃

@gwenn
Copy link
Owner

gwenn commented Nov 25, 2022

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...

@29swastik
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants