HHH-12612 - Fix JDK9 compatibility with TYPE_USE on collection fields.
This commit is contained in:
parent
895b0bb75d
commit
45a3b39c40
|
@ -121,7 +121,14 @@ public final class TypeUtils {
|
|||
return extractClosestRealTypeAsString( compositeUpperBound, context );
|
||||
}
|
||||
else {
|
||||
return context.getTypeUtils().erasure( type ).toString();
|
||||
final TypeMirror erasureType = context.getTypeUtils().erasure( type );
|
||||
if ( TypeKind.ARRAY.equals( erasureType.getKind() ) ) {
|
||||
// keep old behavior here for arrays since #asElement returns null for them.
|
||||
return erasureType.toString();
|
||||
}
|
||||
else {
|
||||
return context.getTypeUtils().asElement( erasureType ).toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* 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.jpamodelgen.test.elementcollection;
|
||||
|
||||
import org.hibernate.jpamodelgen.test.util.CompilationTest;
|
||||
import org.hibernate.jpamodelgen.test.util.TestForIssue;
|
||||
import org.hibernate.jpamodelgen.test.util.WithClasses;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hibernate.jpamodelgen.test.util.TestUtil.assertListAttributeTypeInMetaModelFor;
|
||||
import static org.hibernate.jpamodelgen.test.util.TestUtil.assertMapAttributesInMetaModelFor;
|
||||
import static org.hibernate.jpamodelgen.test.util.TestUtil.assertMetamodelClassGeneratedFor;
|
||||
import static org.hibernate.jpamodelgen.test.util.TestUtil.assertSetAttributeTypeInMetaModelFor;
|
||||
|
||||
/**
|
||||
* @author Chris Cranford
|
||||
*/
|
||||
public class ElementCollectionTypeUseTest extends CompilationTest {
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-12612")
|
||||
@WithClasses(OfficeBuildingValidated.class)
|
||||
public void testAnnotatedCollectionElements() {
|
||||
assertMetamodelClassGeneratedFor( OfficeBuildingValidated.class );
|
||||
|
||||
assertMapAttributesInMetaModelFor(
|
||||
OfficeBuildingValidated.class,
|
||||
"doorCodes",
|
||||
Integer.class,
|
||||
byte[].class,
|
||||
"Wrong type in map attributes."
|
||||
);
|
||||
|
||||
assertSetAttributeTypeInMetaModelFor(
|
||||
OfficeBuildingValidated.class,
|
||||
"computerSerialNumbers",
|
||||
String.class,
|
||||
"Wrong type in set attribute."
|
||||
);
|
||||
|
||||
assertListAttributeTypeInMetaModelFor(
|
||||
OfficeBuildingValidated.class,
|
||||
"employeeNames",
|
||||
String.class,
|
||||
"Wrong type in list attributes."
|
||||
);
|
||||
|
||||
assertListAttributeTypeInMetaModelFor(
|
||||
OfficeBuildingValidated.class,
|
||||
"rooms",
|
||||
Room.class,
|
||||
"Wrong type in list attributes."
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* 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.jpamodelgen.test.elementcollection;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.ElementCollection;
|
||||
import javax.persistence.Entity;
|
||||
|
||||
/**
|
||||
* @author Chris Cranford
|
||||
*/
|
||||
@Entity
|
||||
public class OfficeBuildingValidated {
|
||||
|
||||
// mock a bean validation annotation using TYPE_USE
|
||||
@Target({ ElementType.TYPE_USE })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface NotNullAllowed {
|
||||
|
||||
}
|
||||
|
||||
@ElementCollection
|
||||
@NotNullAllowed
|
||||
private Map<@NotNullAllowed Integer, @NotNullAllowed byte[]> doorCodes;
|
||||
|
||||
@ElementCollection
|
||||
@NotNullAllowed
|
||||
private Set<@NotNullAllowed String> computerSerialNumbers;
|
||||
|
||||
@ElementCollection
|
||||
@NotNullAllowed
|
||||
private List<@NotNullAllowed String> employeeNames;
|
||||
|
||||
@ElementCollection
|
||||
@NotNullAllowed
|
||||
private List<@NotNullAllowed Room> rooms;
|
||||
|
||||
public Map<Integer, byte[]> getDoorCodes() {
|
||||
return doorCodes;
|
||||
}
|
||||
|
||||
public void setDoorCodes(Map<Integer, byte[]> doorCodes) {
|
||||
this.doorCodes = doorCodes;
|
||||
}
|
||||
|
||||
public Set<String> getComputerSerialNumbers() {
|
||||
return computerSerialNumbers;
|
||||
}
|
||||
|
||||
public void setComputerSerialNumbers(Set<String> computerSerialNumbers) {
|
||||
this.computerSerialNumbers = computerSerialNumbers;
|
||||
}
|
||||
|
||||
public List<String> getEmployeeNames() {
|
||||
return employeeNames;
|
||||
}
|
||||
|
||||
public void setEmployeeNames(List<String> employeeNames) {
|
||||
this.employeeNames = employeeNames;
|
||||
}
|
||||
|
||||
public List<Room> getRooms() {
|
||||
return rooms;
|
||||
}
|
||||
|
||||
public void setRooms(List<Room> rooms) {
|
||||
this.rooms = rooms;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue