Skip to content

HHH-16634 Table strategy id generator returns too low id and doesn't honor value from the table #267

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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions orm/hibernate-orm-6/src/test/java/org/hibernate/EntityD.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.hibernate;

import jakarta.persistence.*;

@Entity
public class EntityD {
@Id
@GeneratedValue(generator= "entityD", strategy = GenerationType.TABLE)
@TableGenerator(name = "entityD", table="my_seq",pkColumnName = "my_seq_name", valueColumnName = "my_seq_val")
private Long id;

private String name;

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.Persistence;

import jakarta.persistence.Query;
import org.hibernate.EntityD;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -28,11 +30,29 @@ public void destroy() {
// Entities are auto-discovered, so just add them anywhere on class-path
// Add your tests, using standard JUnit.
@Test
public void hhh123Test() throws Exception {
public void hhh16634Test() throws Exception {
EntityManager entityManager = entityManagerFactory.createEntityManager();
entityManager.getTransaction().begin();
Query nativeQuery = entityManager.createNativeQuery("UPDATE my_seq set my_seq_val=50");
int i = nativeQuery.executeUpdate();
entityManager.getTransaction().commit();
entityManager.getTransaction().begin();
assert i>0;

EntityD entityD = new EntityD();
entityD.setName("abc");
EntityD merge = entityManager.merge(entityD);
System.out.println("*********** ID="+merge.getId());
assert merge.getId()>50;
// Do stuff...
entityManager.getTransaction().commit();
entityManager.getTransaction().begin();
EntityD entityD1 = new EntityD();
entityD1.setName("cde");
EntityD merge1 = entityManager.merge(entityD1);
System.out.println("*********** ID="+merge1.getId());
assert merge1.getId()>50;
entityManager.getTransaction().commit();
entityManager.close();
}
}