Skip to content

Commit

Permalink
test for @SequenceGenerator/@TableGenerator with no name
Browse files Browse the repository at this point in the history
Signed-off-by: Gavin King <gavin@hibernate.org>
  • Loading branch information
gavinking committed May 12, 2024
1 parent f2fe6b6 commit c3a4457
Showing 1 changed file with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.hibernate.orm.test.annotations.id.generators;

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 =
{AnonGeneratorTest.EntityWithAnonSequenceGenerator.class,
AnonGeneratorTest.EntityWithAnonTableGenerator.class})
public class AnonGeneratorTest {
@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;
}
}

0 comments on commit c3a4457

Please sign in to comment.