HHH-11111 - Hibernate does not correctly resolve embeddable in the metamodel
Add test case that proces thaat the issue does not replicate
This commit is contained in:
parent
3a813dcbb4
commit
2d4600bbc7
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.metamodel;
|
||||
|
||||
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class EmbeddableMetaModelTest extends BaseEntityManagerFunctionalTestCase {
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[]{
|
||||
ProductEntity.class
|
||||
};
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-11111")
|
||||
public void testEmbeddableCanBeResolvedWhenUsedAsInterface() {
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
assertNotNull(entityManager.getMetamodel().embeddable(LocalizedValue.class));
|
||||
assertEquals( LocalizedValue.class, ProductEntity_.description.getElementType().getJavaType() );
|
||||
assertNotNull( LocalizedValue_.value );
|
||||
} );
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.metamodel;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
interface ILocalizable extends Serializable {
|
||||
String getValue();
|
||||
|
||||
void setValue(String value);
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.metamodel;
|
||||
|
||||
import java.util.Objects;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Embeddable;
|
||||
|
||||
@Embeddable
|
||||
public class LocalizedValue implements ILocalizable {
|
||||
|
||||
@Column(name = "val")
|
||||
private String value;
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if ( this == o ) {
|
||||
return true;
|
||||
}
|
||||
if ( ( o == null ) || ( getClass() != o.getClass() ) ) {
|
||||
return false;
|
||||
}
|
||||
LocalizedValue that = ( (LocalizedValue) o );
|
||||
return Objects.equals( value, that.value );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash( value );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.metamodel;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.persistence.CollectionTable;
|
||||
import javax.persistence.ElementCollection;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.ForeignKey;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Index;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.MapKeyColumn;
|
||||
|
||||
@Entity
|
||||
public class ProductEntity {
|
||||
|
||||
@Id
|
||||
private Long pk;
|
||||
|
||||
@ElementCollection(targetClass = LocalizedValue.class)
|
||||
@CollectionTable(
|
||||
name = ( "product_name_lv" ),
|
||||
joinColumns = {
|
||||
@JoinColumn(
|
||||
name = ( "product_pk" )
|
||||
)
|
||||
},
|
||||
indexes = {
|
||||
@Index(
|
||||
name = ( "idx_product_name_lv" ),
|
||||
columnList = ( "product_pk" )
|
||||
)
|
||||
},
|
||||
foreignKey =
|
||||
@ForeignKey(
|
||||
name = ( "fk_product_name_lv" )
|
||||
)
|
||||
)
|
||||
@MapKeyColumn(name = "locale")
|
||||
private Map<String, ILocalizable> description = new HashMap<>();
|
||||
|
||||
public Long getPk() {
|
||||
return pk;
|
||||
}
|
||||
|
||||
public void setPk(Long pk) {
|
||||
this.pk = pk;
|
||||
}
|
||||
|
||||
public Map<String, ILocalizable> getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(Map<String, ILocalizable> description) {
|
||||
this.description = description;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue