HHH-11004: Proper handling of array ElementCollection values in jpamodelgen

This commit is contained in:
Bradley Hess 2016-07-28 15:24:19 -04:00 committed by Vlad Mihalcea
parent 731732d780
commit 1be0a347c4
3 changed files with 46 additions and 9 deletions

View File

@ -119,21 +119,20 @@ public class MetaAttributeGenerationVisitor extends SimpleTypeVisitor6<Annotatio
final TypeElement collectionElement = (TypeElement) context.getTypeUtils()
.asElement( collectionElementType );
AccessTypeInformation accessTypeInfo = context.getAccessTypeInfo(
collectionElement.getQualifiedName()
.toString()
);
collectionElementType.toString() );
if ( accessTypeInfo == null ) {
AccessType explicitAccessType = TypeUtils.determineAnnotationSpecifiedAccessType(
AccessType explicitAccessType = null;
if ( collectionElement != null ) {
explicitAccessType = TypeUtils.determineAnnotationSpecifiedAccessType(
collectionElement
);
);
}
accessTypeInfo = new AccessTypeInformation(
collectionElement.getQualifiedName().toString(),
collectionElementType.toString(),
explicitAccessType,
entity.getEntityAccessTypeInfo().getAccessType()
);
context.addAccessTypeInformation(
collectionElement.getQualifiedName().toString(), accessTypeInfo
);
context.addAccessTypeInformation( collectionElementType.toString(), accessTypeInfo );
}
else {
accessTypeInfo.setDefaultAccessType( entity.getEntityAccessTypeInfo().getAccessType() );

View File

@ -15,6 +15,7 @@ import org.junit.Test;
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.assertNoSourceFileGeneratedFor;
import static org.hibernate.jpamodelgen.test.util.TestUtil.assertPresenceOfFieldInMetamodelFor;
/**
* @author Hardy Ferentschik
@ -59,4 +60,14 @@ public class ElementCollectionTest extends CompilationTest {
Hostel.class, "cleaners", Room.class, Cleaner.class, "Wrong type in map attribute."
);
}
@Test
@TestForIssue(jiraKey = "HHH-11004")
@WithClasses({ OfficeBuilding.class })
public void testArrayValueElementCollection() {
assertMetamodelClassGeneratedFor( OfficeBuilding.class );
assertMapAttributesInMetaModelFor(
OfficeBuilding.class, "doorCodes", Integer.class, byte[].class, "Wrong type in map attribute."
);
}
}

View File

@ -0,0 +1,27 @@
/*
* 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.util.Map;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
@Entity
public class OfficeBuilding {
private Map<Integer, byte[]> doorCodes;
@ElementCollection
public Map<Integer, byte[]> getDoorCodes() {
return doorCodes;
}
public void setDoorCodes(Map<Integer, byte[]> doorCodes) {
this.doorCodes = doorCodes;
}
}