Andrea Boriero (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *updated* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiMTBlYTEzYjQ4...
) / Improvement (
https://hibernate.atlassian.net/browse/HHH-15560?atlOrigin=eyJpIjoiMTBlYT...
) HHH-15560 (
https://hibernate.atlassian.net/browse/HHH-15560?atlOrigin=eyJpIjoiMTBlYT...
) Querying Parametrized Embeddable Subclass not supported (
https://hibernate.atlassian.net/browse/HHH-15560?atlOrigin=eyJpIjoiMTBlYT...
)
Change By: Andrea Boriero (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
)
Given the model
{code:java}@MappedSuperclass
public static class Edition<T> {
private String editorName;
@Column(name = "CODE_COLUMN")
private T code;
public Edition() {
}
public Edition(String editorName, T code) {
this.editorName = editorName;
this.code = code;
}
}
@Embeddable
public static class RareEdition extends Edition<Integer> {
private String state;
public RareEdition() {
}
public RareEdition(String editorName, Integer code, String state) {
super( editorName, code );
this.state = state;
}
}
@Embeddable
public static class PopularEdition extends Edition<String> {
@Column(name = "YEAR_COLUMN")
private Integer year;
public PopularEdition() {
}
public PopularEdition(String editorName, String code, Integer year) {
super( editorName, code );
this.year = year;
}
}
@Entity(name = "Base")
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public static class Base {
@Id
private Long id;
public Base() {
}
public Base(Long id) {
this.id = id;
}
}
@MappedSuperclass
public static abstract class Book<T extends Edition> extends Base {
@Embedded
private T edition;
public Book() {
}
public Book(Long id, T edition) {
super( id );
this.edition = edition;
}
}
@Entity(name = "PopularBook")
public static class PopularBook extends Book<PopularEdition> {
public PopularBook() {
}
public PopularBook(Long id, PopularEdition edition) {
super( id, edition );
}
}
@Entity(name = "RareBook")
public static class RareBook extends Book<RareEdition> {
public RareBook() {
}
public RareBook(Long id, RareEdition edition) {
super( id, edition );
}
}{code}
the following test fails
{code:java}@Test
@FailureExpected(jiraKey = "", reason = "Parametrized Embedded Subclasses
not supported")
public void testSelectSpecificEmbeddedAttribute(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
List<String> rareBookCodes = session.createQuery(
"select b.edition.state from RareBook b where b.id = :id",
String.class
).setParameter( "id", RARE_BOOK_ID ).list();
assertThat( rareBookCodes.size() ).isEqualTo( 1 );
String code = rareBookCodes.get( 0 );
assertThat( code ).isEqualTo( RARE_BOOK_STATE );
}
);
scope.inTransaction(
session -> {
List<Integer> populareBookCodes = session.createQuery(
"select b.edition.year from PopularBook b where b.id = :id",
Integer.class
).setParameter( "id", POPULAR_BOOK_ID ).list();
assertThat( populareBookCodes.size() ).isEqualTo( 1 );
Integer code = populareBookCodes.get( 0 );
assertThat( code ).isEqualTo( POPULAR_BOOK_YEAR );
}
);
}
{code}
[Test
case|https://github.com/hibernate/hibernate-orm/pull/5358]
(
https://hibernate.atlassian.net/browse/HHH-15560#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-15560#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100207- sha1:ee9e30a )