diff --git a/hibernate-core/src/test/java/org/hibernate/test/mapping/hhh14343/NestedIdClassTest.java b/hibernate-core/src/test/java/org/hibernate/test/mapping/hhh14343/NestedIdClassTest.java new file mode 100644 index 0000000000..5bfd876f6e --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/mapping/hhh14343/NestedIdClassTest.java @@ -0,0 +1,55 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.test.mapping.hhh14343; + +import org.hibernate.cfg.AvailableSettings; +import org.hibernate.hql.spi.id.inline.InlineIdsOrClauseBulkIdStrategy; +import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; +import org.hibernate.test.mapping.hhh14343.entity.NestedPlayerStat; +import org.hibernate.test.mapping.hhh14343.entity.NestedScore; +import org.hibernate.test.mapping.hhh14343.entity.NestedStat; +import org.hibernate.testing.TestForIssue; +import org.junit.Before; +import org.junit.Test; + +import java.util.Map; + +import static org.hibernate.testing.transaction.TransactionUtil.doInJPA; + +@TestForIssue(jiraKey = "HHH-14343") +public class NestedIdClassTest extends BaseEntityManagerFunctionalTestCase { + @Override + protected Class[] getAnnotatedClasses() { + return new Class[] { + NestedStat.class, + NestedPlayerStat.class, + NestedScore.class + }; + } + + @Override + protected void addConfigOptions(Map options) { + options.put( AvailableSettings.GLOBALLY_QUOTED_IDENTIFIERS, Boolean.TRUE ); + options.put( AvailableSettings.HQL_BULK_ID_STRATEGY, InlineIdsOrClauseBulkIdStrategy.class.getName() ); + } + + @Before + public void setUp() { + doInJPA( this::entityManagerFactory, em -> + { + // do nothing + } ); + } + + @Test + public void testNestedIdClasses() { + doInJPA( this::entityManagerFactory, em -> + { + // do nothing + } ); + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/mapping/hhh14343/entity/NestedPlayerStat.java b/hibernate-core/src/test/java/org/hibernate/test/mapping/hhh14343/entity/NestedPlayerStat.java new file mode 100644 index 0000000000..a10564cc09 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/mapping/hhh14343/entity/NestedPlayerStat.java @@ -0,0 +1,69 @@ +package org.hibernate.test.mapping.hhh14343.entity; + +import java.io.Serializable; + +import javax.persistence.Basic; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.Id; +import javax.persistence.IdClass; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + +@Entity +@Table(name = "\"PlayerStats\"") +@IdClass(NestedPlayerStatId.class) +public class NestedPlayerStat implements Serializable +{ + private static final long serialVersionUID = 1L; + + @Id + @Column(name = "player_id") + private Integer playerId; + + @Basic(optional = false) + @Column(name = "jersey_nbr") + private Integer jerseyNbr; + + @Id + @ManyToOne(optional = false, fetch = FetchType.EAGER) + @JoinColumn(name = "game_id", referencedColumnName = "game_id") + @JoinColumn(name = "is_home", referencedColumnName = "is_home") + private NestedScore score; + + public NestedPlayerStat() + { + } + + public Integer getPlayerId() + { + return playerId; + } + + public void setPlayerId(Integer playerId) + { + this.playerId = playerId; + } + + public Integer getJerseyNbr() + { + return jerseyNbr; + } + + public void setJerseyNbr(Integer jerseyNbr) + { + this.jerseyNbr = jerseyNbr; + } + + public NestedScore getScore() + { + return score; + } + + public void setScore(NestedScore score) + { + this.score = score; + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/mapping/hhh14343/entity/NestedPlayerStatId.java b/hibernate-core/src/test/java/org/hibernate/test/mapping/hhh14343/entity/NestedPlayerStatId.java new file mode 100644 index 0000000000..5a93f44e16 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/mapping/hhh14343/entity/NestedPlayerStatId.java @@ -0,0 +1,36 @@ +package org.hibernate.test.mapping.hhh14343.entity; + +import java.io.Serializable; + +public class NestedPlayerStatId implements Serializable +{ + private static final long serialVersionUID = 1L; + + private Integer playerId; + + private NestedScoreId score; + + public NestedPlayerStatId() + { + } + + public Integer getPlayerId() + { + return playerId; + } + + public void setPlayerId(Integer playerId) + { + this.playerId = playerId; + } + + public NestedScoreId getScore() + { + return score; + } + + public void setScore(NestedScoreId score) + { + this.score = score; + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/mapping/hhh14343/entity/NestedScore.java b/hibernate-core/src/test/java/org/hibernate/test/mapping/hhh14343/entity/NestedScore.java new file mode 100644 index 0000000000..022dd21eda --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/mapping/hhh14343/entity/NestedScore.java @@ -0,0 +1,78 @@ +package org.hibernate.test.mapping.hhh14343.entity; + +import java.io.Serializable; + +import javax.persistence.Basic; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.IdClass; +import javax.persistence.Table; + +@Entity +@Table(name = "\"Scores\"") +@IdClass(NestedScoreId.class) +public class NestedScore implements Serializable +{ + private static final long serialVersionUID = 1L; + + @Id + @Column(name = "game_id") + private Integer gameId; + + @Id + @Column(name = "is_home") + private Boolean home; + + @Basic(optional = false) + @Column(name = "roster_id") + private Integer rosterId; + + @Basic + @Column(name = "final_score") + private Integer finalScore; + + public NestedScore() + { + } + + public Integer getGameId() + { + return gameId; + } + + public void setGameId(Integer gameId) + { + this.gameId = gameId; + } + + public Boolean getHome() + { + return home; + } + + public void setHome(Boolean home) + { + this.home = home; + } + + public Integer getRosterId() + { + return rosterId; + } + + public void setRosterId(Integer rosterId) + { + this.rosterId = rosterId; + } + + public Integer getFinalScore() + { + return finalScore; + } + + public void setFinalScore(Integer finalScore) + { + this.finalScore = finalScore; + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/mapping/hhh14343/entity/NestedScoreId.java b/hibernate-core/src/test/java/org/hibernate/test/mapping/hhh14343/entity/NestedScoreId.java new file mode 100644 index 0000000000..d5ba2be163 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/mapping/hhh14343/entity/NestedScoreId.java @@ -0,0 +1,36 @@ +package org.hibernate.test.mapping.hhh14343.entity; + +import java.io.Serializable; + +public class NestedScoreId implements Serializable +{ + private static final long serialVersionUID = 1L; + + private Integer gameId; + + private Boolean home; + + public NestedScoreId() + { + } + + public Integer getGameId() + { + return gameId; + } + + public void setGameId(Integer gameId) + { + this.gameId = gameId; + } + + public Boolean getHome() + { + return home; + } + + public void setHome(Boolean home) + { + this.home = home; + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/mapping/hhh14343/entity/NestedStat.java b/hibernate-core/src/test/java/org/hibernate/test/mapping/hhh14343/entity/NestedStat.java new file mode 100644 index 0000000000..a41c300dc4 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/mapping/hhh14343/entity/NestedStat.java @@ -0,0 +1,55 @@ +package org.hibernate.test.mapping.hhh14343.entity; + +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.Id; +import javax.persistence.IdClass; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + +@Entity +@Table(name = "\"Stats\"") +@IdClass(NestedStatId.class) +public class NestedStat implements Serializable +{ + private static final long serialVersionUID = 1L; + + @Id + @Column + private Integer period; + + @Id + @ManyToOne(optional = false, fetch = FetchType.EAGER) + @JoinColumn(name = "game_id", referencedColumnName = "game_id") + @JoinColumn(name = "is_home", referencedColumnName = "is_home") + @JoinColumn(name = "player_id", referencedColumnName = "player_id") + private NestedPlayerStat playerStat; + + public NestedStat() + { + } + + public Integer getPeriod() + { + return period; + } + + public void setPeriod(Integer period) + { + this.period = period; + } + + public NestedPlayerStat getPlayerStat() + { + return playerStat; + } + + public void setPlayerStat(NestedPlayerStat playerStat) + { + this.playerStat = playerStat; + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/mapping/hhh14343/entity/NestedStatId.java b/hibernate-core/src/test/java/org/hibernate/test/mapping/hhh14343/entity/NestedStatId.java new file mode 100644 index 0000000000..0ffb0d100a --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/mapping/hhh14343/entity/NestedStatId.java @@ -0,0 +1,36 @@ +package org.hibernate.test.mapping.hhh14343.entity; + +import java.io.Serializable; + +public class NestedStatId implements Serializable +{ + private static final long serialVersionUID = 1L; + + private Integer period; + + private NestedPlayerStatId playerStat; + + public NestedStatId() + { + } + + public Integer getPeriod() + { + return period; + } + + public void setPeriod(Integer period) + { + this.period = period; + } + + public NestedPlayerStatId getPlayerStat() + { + return playerStat; + } + + public void setPlayerStat(NestedPlayerStatId playerStat) + { + this.playerStat = playerStat; + } +}