|
| 1 | +/* |
| 2 | + * SPDX-License-Identifier: LGPL-2.1-or-later |
| 3 | + * Copyright Red Hat Inc. and Hibernate Authors |
| 4 | + */ |
| 5 | +package org.hibernate.orm.test.schema; |
| 6 | + |
| 7 | +import jakarta.persistence.Column; |
| 8 | +import jakarta.persistence.Entity; |
| 9 | +import jakarta.persistence.GeneratedValue; |
| 10 | +import jakarta.persistence.GenerationType; |
| 11 | +import jakarta.persistence.Id; |
| 12 | +import jakarta.persistence.JoinColumn; |
| 13 | +import jakarta.persistence.ManyToOne; |
| 14 | +import org.hibernate.dialect.H2Dialect; |
| 15 | +import org.hibernate.testing.orm.junit.EntityManagerFactoryScope; |
| 16 | +import org.hibernate.testing.orm.junit.JiraKey; |
| 17 | +import org.hibernate.testing.orm.junit.Jpa; |
| 18 | +import org.hibernate.testing.orm.junit.RequiresDialect; |
| 19 | +import org.junit.jupiter.api.Test; |
| 20 | + |
| 21 | +@Jpa(annotatedClasses = {JoinColumnDefinitionTest.Entity1.class, JoinColumnDefinitionTest.Entity2.class}) |
| 22 | +@RequiresDialect(H2Dialect.class) |
| 23 | +class JoinColumnDefinitionTest { |
| 24 | + |
| 25 | + @Test @JiraKey("HHH-19118") |
| 26 | + void hhh19118test(EntityManagerFactoryScope scope) { |
| 27 | + scope.inTransaction( entityManager -> { |
| 28 | + entityManager.persist(new Entity1()); |
| 29 | + entityManager.persist(new Entity2()); |
| 30 | + } ); |
| 31 | + } |
| 32 | + |
| 33 | + @Entity |
| 34 | + public static class Entity1 { |
| 35 | + |
| 36 | + @Id |
| 37 | + @Column(columnDefinition = "bigint not null generated by default as identity") |
| 38 | + @GeneratedValue(strategy = GenerationType.IDENTITY) |
| 39 | + Long id; |
| 40 | + |
| 41 | + @JoinColumn(columnDefinition = "bigint comment 'entity2 ID'") |
| 42 | + @ManyToOne |
| 43 | + Entity2 entity2; |
| 44 | + } |
| 45 | + |
| 46 | + @Entity |
| 47 | + public static class Entity2 { |
| 48 | + |
| 49 | + @Id |
| 50 | + @Column(columnDefinition = "bigint not null generated by default as identity") |
| 51 | + @GeneratedValue(strategy = GenerationType.IDENTITY) |
| 52 | + Long id; |
| 53 | + |
| 54 | + String name; |
| 55 | + } |
| 56 | +} |
0 commit comments