Skip to content

Commit 44ca255

Browse files
info@kawoolutions.comSanne
info@kawoolutions.com
authored andcommitted
HHH-14276 test case for strange AnnotationException: MapsId in IdClass context
1 parent aa0c9d1 commit 44ca255

File tree

5 files changed

+313
-0
lines changed

5 files changed

+313
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package org.hibernate.test.mapping.hhh14276;
2+
3+
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
4+
5+
import java.util.Map;
6+
7+
import org.hibernate.cfg.AvailableSettings;
8+
import org.hibernate.hql.spi.id.inline.InlineIdsOrClauseBulkIdStrategy;
9+
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
10+
import org.hibernate.test.mapping.hhh14276.entity.PlayerStat;
11+
import org.hibernate.test.mapping.hhh14276.entity.Score;
12+
import org.hibernate.testing.TestForIssue;
13+
import org.junit.Before;
14+
import org.junit.Test;
15+
16+
/**
17+
* This template demonstrates how to develop a test case for Hibernate ORM, using the Java Persistence API.
18+
*/
19+
@TestForIssue( jiraKey = "HHH-14276" )
20+
public class NestedIdClassDerivedIdentifiersTest extends BaseEntityManagerFunctionalTestCase
21+
{
22+
@Override
23+
protected Class<?>[] getAnnotatedClasses()
24+
{
25+
return new Class<?>[] { PlayerStat.class,
26+
Score.class };
27+
}
28+
29+
@Override
30+
protected void addConfigOptions( Map options )
31+
{
32+
options.put( AvailableSettings.GLOBALLY_QUOTED_IDENTIFIERS, Boolean.TRUE );
33+
options.put( AvailableSettings.HQL_BULK_ID_STRATEGY, InlineIdsOrClauseBulkIdStrategy.class.getName() );
34+
}
35+
36+
@Before
37+
public void setUp()
38+
{
39+
doInJPA( this::entityManagerFactory, em ->
40+
{
41+
// do nothing
42+
} );
43+
}
44+
45+
@Test
46+
public void testNestedIdClassDerivedIdentifiers() throws Exception
47+
{
48+
doInJPA( this::entityManagerFactory, em ->
49+
{
50+
// do nothing
51+
});
52+
}
53+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package org.hibernate.test.mapping.hhh14276.entity;
2+
3+
import java.io.Serializable;
4+
5+
import javax.persistence.Basic;
6+
import javax.persistence.Column;
7+
import javax.persistence.Entity;
8+
import javax.persistence.FetchType;
9+
import javax.persistence.Id;
10+
import javax.persistence.IdClass;
11+
import javax.persistence.JoinColumn;
12+
import javax.persistence.ManyToOne;
13+
import javax.persistence.Table;
14+
15+
@Entity
16+
@Table(name = "\"PlayerStats\"")
17+
@IdClass(PlayerStatId.class)
18+
public class PlayerStat implements Serializable
19+
{
20+
private static final long serialVersionUID = 1L;
21+
22+
@Id
23+
@Column(name = "player_id")
24+
private Integer playerId;
25+
26+
@Basic(optional = false)
27+
@Column(name = "jersey_nbr")
28+
private Integer jerseyNbr;
29+
30+
@Id
31+
@ManyToOne(optional = false, fetch = FetchType.EAGER)
32+
@JoinColumn(name = "game_id", referencedColumnName = "game_id")
33+
@JoinColumn(name = "is_home", referencedColumnName = "is_home")
34+
private Score score;
35+
36+
public PlayerStat()
37+
{
38+
}
39+
40+
public Integer getGameId()
41+
{
42+
return score.getGameId();
43+
}
44+
45+
public void setGameId(Integer gameId)
46+
{
47+
score.setGameId(gameId);
48+
}
49+
50+
public Boolean getHome()
51+
{
52+
return score.getHome();
53+
}
54+
55+
public void setHome(Boolean home)
56+
{
57+
score.setHome(home);
58+
}
59+
60+
public Integer getPlayerId()
61+
{
62+
return playerId;
63+
}
64+
65+
public void setPlayerId(Integer playerId)
66+
{
67+
this.playerId = playerId;
68+
}
69+
70+
public Integer getJerseyNbr()
71+
{
72+
return jerseyNbr;
73+
}
74+
75+
public void setJerseyNbr(Integer jerseyNbr)
76+
{
77+
this.jerseyNbr = jerseyNbr;
78+
}
79+
80+
public Score getScore()
81+
{
82+
return score;
83+
}
84+
85+
public void setScore(Score score)
86+
{
87+
this.score = score;
88+
}
89+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package org.hibernate.test.mapping.hhh14276.entity;
2+
3+
import java.io.Serializable;
4+
5+
public class PlayerStatId implements Serializable
6+
{
7+
private static final long serialVersionUID = 1L;
8+
9+
private Integer playerId;
10+
11+
// nested composite PK @IdClass: named like relationship in entity class
12+
private ScoreId score;
13+
14+
public PlayerStatId()
15+
{
16+
}
17+
18+
public Integer getGameId()
19+
{
20+
return score.getGameId();
21+
}
22+
23+
public void setGameId(Integer gameId)
24+
{
25+
score.setGameId(gameId);
26+
}
27+
28+
public Boolean getHome()
29+
{
30+
return score.getHome();
31+
}
32+
33+
public void setHome(Boolean home)
34+
{
35+
score.setHome(home);
36+
}
37+
38+
public Integer getPlayerId()
39+
{
40+
return playerId;
41+
}
42+
43+
public void setPlayerId(Integer playerId)
44+
{
45+
this.playerId = playerId;
46+
}
47+
48+
public ScoreId getScoreId()
49+
{
50+
return score;
51+
}
52+
53+
public void setScoreId(ScoreId scoreId)
54+
{
55+
this.score = scoreId;
56+
}
57+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package org.hibernate.test.mapping.hhh14276.entity;
2+
3+
import java.io.Serializable;
4+
5+
import javax.persistence.Basic;
6+
import javax.persistence.Column;
7+
import javax.persistence.Entity;
8+
import javax.persistence.Id;
9+
import javax.persistence.IdClass;
10+
import javax.persistence.Table;
11+
12+
@Entity
13+
@Table(name = "\"Scores\"")
14+
@IdClass(ScoreId.class)
15+
public class Score implements Serializable
16+
{
17+
private static final long serialVersionUID = 1L;
18+
19+
@Id
20+
@Column(name = "game_id")
21+
private Integer gameId;
22+
23+
@Id
24+
@Column(name = "is_home")
25+
private Boolean home;
26+
27+
@Basic(optional = false)
28+
@Column(name = "roster_id")
29+
private Integer rosterId;
30+
31+
@Basic
32+
@Column(name = "final_score")
33+
private Integer finalScore;
34+
35+
public Score()
36+
{
37+
}
38+
39+
public Integer getGameId()
40+
{
41+
return gameId;
42+
}
43+
44+
public void setGameId(Integer gameId)
45+
{
46+
this.gameId = gameId;
47+
}
48+
49+
public Boolean getHome()
50+
{
51+
return home;
52+
}
53+
54+
public void setHome(Boolean home)
55+
{
56+
this.home = home;
57+
}
58+
59+
public Integer getRosterId()
60+
{
61+
return rosterId;
62+
}
63+
64+
public void setRosterId(Integer rosterId)
65+
{
66+
this.rosterId = rosterId;
67+
}
68+
69+
public Integer getFinalScore()
70+
{
71+
return finalScore;
72+
}
73+
74+
public void setFinalScore(Integer finalScore)
75+
{
76+
this.finalScore = finalScore;
77+
}
78+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package org.hibernate.test.mapping.hhh14276.entity;
2+
3+
import java.io.Serializable;
4+
5+
public class ScoreId implements Serializable
6+
{
7+
private static final long serialVersionUID = 1L;
8+
9+
private Integer gameId;
10+
11+
private Boolean home;
12+
13+
public ScoreId()
14+
{
15+
}
16+
17+
public Integer getGameId()
18+
{
19+
return gameId;
20+
}
21+
22+
public void setGameId(Integer gameId)
23+
{
24+
this.gameId = gameId;
25+
}
26+
27+
public Boolean getHome()
28+
{
29+
return home;
30+
}
31+
32+
public void setHome(Boolean home)
33+
{
34+
this.home = home;
35+
}
36+
}

0 commit comments

Comments
 (0)