test for @SequenceGenerator/@TableGenerator with no name

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-05-12 17:41:50 +02:00 committed by Steve Ebersole
parent 3c161e0c82
commit 27042f562f
4 changed files with 137 additions and 0 deletions

View File

@ -0,0 +1,45 @@
package org.hibernate.orm.test.annotations.id.generators.entity;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.SequenceGenerator;
import jakarta.persistence.TableGenerator;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
@SessionFactory
@DomainModel(annotatedClasses =
{ClassLevelGeneratorTest.EntityWithAnonSequenceGenerator.class,
ClassLevelGeneratorTest.EntityWithAnonTableGenerator.class})
public class ClassLevelGeneratorTest {
@Test
void testAnonGenerator(SessionFactoryScope scope) {
scope.inSession(s-> {
EntityWithAnonSequenceGenerator entity1 = new EntityWithAnonSequenceGenerator();
EntityWithAnonTableGenerator entity2 = new EntityWithAnonTableGenerator();
s.persist(entity1);
s.persist(entity2);
assertEquals(42, entity1.id);
assertEquals(69, entity2.id);
});
}
@Entity
@SequenceGenerator(initialValue = 42)
static class EntityWithAnonSequenceGenerator {
@Id
@GeneratedValue
long id;
}
@Entity
@TableGenerator(initialValue = 69)
static class EntityWithAnonTableGenerator {
@Id
@GeneratedValue
long id;
}
}

View File

@ -0,0 +1,45 @@
package org.hibernate.orm.test.annotations.id.generators.entity;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.SequenceGenerator;
import jakarta.persistence.TableGenerator;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
@SessionFactory
@DomainModel(annotatedClasses =
{FieldLevelGeneratorTest.EntityWithAnonSequenceGenerator.class,
FieldLevelGeneratorTest.EntityWithAnonTableGenerator.class})
public class FieldLevelGeneratorTest {
@Test
void testAnonGenerator(SessionFactoryScope scope) {
scope.inSession(s-> {
EntityWithAnonSequenceGenerator entity1 = new EntityWithAnonSequenceGenerator();
EntityWithAnonTableGenerator entity2 = new EntityWithAnonTableGenerator();
s.persist(entity1);
s.persist(entity2);
assertEquals(42, entity1.id);
assertEquals(69, entity2.id);
});
}
@Entity
static class EntityWithAnonSequenceGenerator {
@Id
@GeneratedValue
@SequenceGenerator(initialValue = 42)
long id;
}
@Entity
static class EntityWithAnonTableGenerator {
@Id
@GeneratedValue
@TableGenerator(initialValue = 69)
long id;
}
}

View File

@ -0,0 +1,41 @@
package org.hibernate.orm.test.annotations.id.generators.pkg;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
@SessionFactory
@DomainModel(annotatedClasses =
{PackageLevelGeneratorTest.EntityWithAnonSequenceGenerator.class,
PackageLevelGeneratorTest.EntityWithAnonTableGenerator.class})
public class PackageLevelGeneratorTest {
@Test
void testAnonGenerator(SessionFactoryScope scope) {
scope.inSession(s-> {
EntityWithAnonSequenceGenerator entity1 = new EntityWithAnonSequenceGenerator();
EntityWithAnonTableGenerator entity2 = new EntityWithAnonTableGenerator();
s.persist(entity1);
s.persist(entity2);
assertEquals(42, entity1.id);
assertEquals(69, entity2.id);
});
}
@Entity
static class EntityWithAnonSequenceGenerator {
@Id
@GeneratedValue
long id;
}
@Entity
static class EntityWithAnonTableGenerator {
@Id
@GeneratedValue
long id;
}
}

View File

@ -0,0 +1,6 @@
@SequenceGenerator(initialValue = 42)
@TableGenerator(initialValue = 69)
package org.hibernate.orm.test.annotations.id.generators.pkg;
import jakarta.persistence.SequenceGenerator;
import jakarta.persistence.TableGenerator;