-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test for @SequenceGenerator/@TableGenerator with no name
Signed-off-by: Gavin King <gavin@hibernate.org>
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
...ore/src/test/java/org/hibernate/orm/test/annotations/id/generators/AnonGeneratorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |