-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HHH-7135 Tests for derived identity with joined inheritance
- Loading branch information
Showing
3 changed files
with
381 additions
and
0 deletions.
There are no files selected for viewing
125 changes: 125 additions & 0 deletions
125
...ibernate/orm/test/annotations/derivedidentities/DerivedIdentityJoinedInheritanceTest.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,125 @@ | ||
/* | ||
* SPDX-License-Identifier: LGPL-2.1-or-later | ||
* Copyright Red Hat Inc. and Hibernate Authors | ||
*/ | ||
package org.hibernate.orm.test.annotations.derivedidentities; | ||
|
||
import jakarta.persistence.Basic; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Inheritance; | ||
import jakarta.persistence.InheritanceType; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.OneToOne; | ||
import org.hibernate.testing.orm.junit.DomainModel; | ||
import org.hibernate.testing.orm.junit.Jira; | ||
import org.hibernate.testing.orm.junit.SessionFactory; | ||
import org.hibernate.testing.orm.junit.SessionFactoryScope; | ||
import org.junit.jupiter.api.Test; | ||
|
||
|
||
@DomainModel( | ||
annotatedClasses = { | ||
DerivedIdentityJoinedInheritanceTest.ThingHolder.class, DerivedIdentityJoinedInheritanceTest.AThing.class, DerivedIdentityJoinedInheritanceTest.Thing1.class, DerivedIdentityJoinedInheritanceTest.Thing2.class | ||
} | ||
) | ||
@SessionFactory | ||
@Jira("https://hibernate.atlassian.net/browse/HHH-7135") | ||
public class DerivedIdentityJoinedInheritanceTest { | ||
|
||
@Test | ||
public void testInsertIntoMap(SessionFactoryScope scope) { | ||
scope.inTransaction( | ||
session -> { | ||
ThingHolder holder = new ThingHolder(); | ||
Thing1 thing1 = new Thing1( holder, "test" ); | ||
session.persist( holder ); | ||
session.persist( thing1 ); | ||
} | ||
); | ||
|
||
} | ||
|
||
@Entity(name = "AThing") | ||
@Inheritance(strategy = InheritanceType.JOINED) | ||
public abstract class AThing { | ||
public AThing() { | ||
} | ||
|
||
public AThing(ThingHolder holder) { | ||
this.holder = holder; | ||
} | ||
|
||
@Id | ||
@OneToOne | ||
@JoinColumn(name = "id") | ||
private ThingHolder holder; | ||
|
||
public ThingHolder getHolder() { | ||
return holder; | ||
} | ||
} | ||
|
||
@Entity(name = "ThingHolder") | ||
public class ThingHolder { | ||
public ThingHolder() { | ||
} | ||
|
||
@Id | ||
@GeneratedValue | ||
private Integer id; | ||
@OneToOne | ||
private AThing thing; | ||
|
||
public Integer getId() { | ||
return id; | ||
} | ||
|
||
public AThing getThing() { | ||
return thing; | ||
} | ||
|
||
public void setThing(AThing thing) { | ||
this.thing = thing; | ||
} | ||
} | ||
|
||
@Entity(name = "Thing1") | ||
public class Thing1 extends AThing { | ||
public Thing1() { | ||
super(); | ||
} | ||
|
||
public Thing1(ThingHolder holder, String string) { | ||
super( holder ); | ||
this.string = string; | ||
} | ||
|
||
@Basic | ||
private String string; | ||
|
||
public String getString() { | ||
return string; | ||
} | ||
} | ||
|
||
@Entity(name = "Thing2") | ||
public class Thing2 extends AThing { | ||
public Thing2() { | ||
super(); | ||
} | ||
|
||
public Thing2(ThingHolder holder, Integer integer) { | ||
super( holder ); | ||
this.integer = integer; | ||
} | ||
|
||
@Basic | ||
private Integer integer; | ||
|
||
public Integer getInteger() { | ||
return integer; | ||
} | ||
} | ||
} |
130 changes: 130 additions & 0 deletions
130
...ava/org/hibernate/orm/test/annotations/derivedidentities/MapsIdJoinedInheritanceTest.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,130 @@ | ||
/* | ||
* SPDX-License-Identifier: LGPL-2.1-or-later | ||
* Copyright Red Hat Inc. and Hibernate Authors | ||
*/ | ||
package org.hibernate.orm.test.annotations.derivedidentities; | ||
|
||
import jakarta.persistence.Basic; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Inheritance; | ||
import jakarta.persistence.InheritanceType; | ||
import jakarta.persistence.MapsId; | ||
import jakarta.persistence.OneToOne; | ||
import org.hibernate.testing.orm.junit.DomainModel; | ||
import org.hibernate.testing.orm.junit.Jira; | ||
import org.hibernate.testing.orm.junit.SessionFactory; | ||
import org.hibernate.testing.orm.junit.SessionFactoryScope; | ||
import org.junit.jupiter.api.Test; | ||
|
||
|
||
@DomainModel( | ||
annotatedClasses = { | ||
MapsIdJoinedInheritanceTest.ThingHolder.class, MapsIdJoinedInheritanceTest.AThing.class, MapsIdJoinedInheritanceTest.Thing1.class, MapsIdJoinedInheritanceTest.Thing2.class | ||
} | ||
) | ||
@SessionFactory | ||
@Jira("https://hibernate.atlassian.net/browse/HHH-7135") | ||
public class MapsIdJoinedInheritanceTest { | ||
|
||
@Test | ||
public void testInsertIntoMap(SessionFactoryScope scope) { | ||
scope.inTransaction( | ||
session -> { | ||
ThingHolder holder = new ThingHolder(); | ||
Thing1 thing1 = new Thing1( holder, "test" ); | ||
session.persist( holder ); | ||
session.persist( thing1 ); | ||
} | ||
); | ||
|
||
} | ||
|
||
@Entity(name = "AThing") | ||
@Inheritance(strategy = InheritanceType.JOINED) | ||
public abstract class AThing { | ||
public AThing() { | ||
} | ||
|
||
public AThing(ThingHolder holder) { | ||
this.holder = holder; | ||
} | ||
|
||
@Id | ||
private Integer id; | ||
@MapsId | ||
@OneToOne | ||
private ThingHolder holder; | ||
|
||
public Integer getId() { | ||
return id; | ||
} | ||
|
||
public ThingHolder getHolder() { | ||
return holder; | ||
} | ||
} | ||
|
||
@Entity(name = "ThingHolder") | ||
public class ThingHolder { | ||
public ThingHolder() { | ||
} | ||
|
||
@Id | ||
@GeneratedValue | ||
private Integer id; | ||
@OneToOne | ||
private AThing thing; | ||
|
||
public Integer getId() { | ||
return id; | ||
} | ||
|
||
public AThing getThing() { | ||
return thing; | ||
} | ||
|
||
public void setThing(AThing thing) { | ||
this.thing = thing; | ||
} | ||
} | ||
|
||
@Entity(name = "Thing1") | ||
public class Thing1 extends AThing { | ||
public Thing1() { | ||
super(); | ||
} | ||
|
||
public Thing1(ThingHolder holder, String string) { | ||
super( holder ); | ||
this.string = string; | ||
} | ||
|
||
@Basic | ||
private String string; | ||
|
||
public String getString() { | ||
return string; | ||
} | ||
} | ||
|
||
@Entity(name = "Thing2") | ||
public class Thing2 extends AThing { | ||
public Thing2() { | ||
super(); | ||
} | ||
|
||
public Thing2(ThingHolder holder, Integer integer) { | ||
super( holder ); | ||
this.integer = integer; | ||
} | ||
|
||
@Basic | ||
private Integer integer; | ||
|
||
public Integer getInteger() { | ||
return integer; | ||
} | ||
} | ||
} |
126 changes: 126 additions & 0 deletions
126
.../java/org/hibernate/orm/test/annotations/derivedidentities/MapsIdUnownedOneToOneTest.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,126 @@ | ||
/* | ||
* SPDX-License-Identifier: LGPL-2.1-or-later | ||
* Copyright Red Hat Inc. and Hibernate Authors | ||
*/ | ||
package org.hibernate.orm.test.annotations.derivedidentities; | ||
|
||
import jakarta.persistence.Basic; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Inheritance; | ||
import jakarta.persistence.InheritanceType; | ||
import jakarta.persistence.MapsId; | ||
import jakarta.persistence.OneToOne; | ||
import org.hibernate.AnnotationException; | ||
import org.hibernate.boot.MetadataSources; | ||
import org.hibernate.testing.orm.junit.Jira; | ||
import org.hibernate.testing.orm.junit.ServiceRegistry; | ||
import org.hibernate.testing.orm.junit.ServiceRegistryScope; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.Assert.fail; | ||
|
||
@ServiceRegistry | ||
@Jira("https://hibernate.atlassian.net/browse/HHH-7135") | ||
public class MapsIdUnownedOneToOneTest { | ||
|
||
@Test | ||
public void testInvalidMapping(ServiceRegistryScope scope) { | ||
MetadataSources metadataSources = new MetadataSources( scope.getRegistry() ) | ||
.addAnnotatedClasses( MapsIdUnownedOneToOneTest.ThingHolder.class, MapsIdUnownedOneToOneTest.AThing.class, MapsIdUnownedOneToOneTest.Thing1.class, MapsIdUnownedOneToOneTest.Thing2.class ); | ||
try { | ||
metadataSources.buildMetadata(); | ||
fail( "Was expecting failure" ); | ||
} | ||
catch (AnnotationException ignore) { | ||
} | ||
} | ||
|
||
@Entity(name = "AThing") | ||
@Inheritance(strategy = InheritanceType.JOINED) | ||
public abstract class AThing { | ||
public AThing() { | ||
} | ||
|
||
public AThing(ThingHolder holder) { | ||
this.holder = holder; | ||
} | ||
|
||
@Id | ||
private Integer id; | ||
@MapsId | ||
@OneToOne(mappedBy = "thing") | ||
private ThingHolder holder; | ||
|
||
public Integer getId() { | ||
return id; | ||
} | ||
|
||
public ThingHolder getHolder() { | ||
return holder; | ||
} | ||
} | ||
|
||
@Entity(name = "ThingHolder") | ||
public class ThingHolder { | ||
public ThingHolder() { | ||
} | ||
|
||
@Id | ||
@GeneratedValue | ||
private Integer id; | ||
@OneToOne | ||
private AThing thing; | ||
|
||
public Integer getId() { | ||
return id; | ||
} | ||
|
||
public AThing getThing() { | ||
return thing; | ||
} | ||
|
||
public void setThing(AThing thing) { | ||
this.thing = thing; | ||
} | ||
} | ||
|
||
@Entity(name = "Thing1") | ||
public class Thing1 extends AThing { | ||
public Thing1() { | ||
super(); | ||
} | ||
|
||
public Thing1(ThingHolder holder, String string) { | ||
super( holder ); | ||
this.string = string; | ||
} | ||
|
||
@Basic | ||
private String string; | ||
|
||
public String getString() { | ||
return string; | ||
} | ||
} | ||
|
||
@Entity(name = "Thing2") | ||
public class Thing2 extends AThing { | ||
public Thing2() { | ||
super(); | ||
} | ||
|
||
public Thing2(ThingHolder holder, Integer integer) { | ||
super( holder ); | ||
this.integer = integer; | ||
} | ||
|
||
@Basic | ||
private Integer integer; | ||
|
||
public Integer getInteger() { | ||
return integer; | ||
} | ||
} | ||
} |