HHH-11004: Proper handling of array ElementCollection values in jpamodelgen
This commit is contained in:
parent
731732d780
commit
1be0a347c4
|
@ -119,21 +119,20 @@ public class MetaAttributeGenerationVisitor extends SimpleTypeVisitor6<Annotatio
|
||||||
final TypeElement collectionElement = (TypeElement) context.getTypeUtils()
|
final TypeElement collectionElement = (TypeElement) context.getTypeUtils()
|
||||||
.asElement( collectionElementType );
|
.asElement( collectionElementType );
|
||||||
AccessTypeInformation accessTypeInfo = context.getAccessTypeInfo(
|
AccessTypeInformation accessTypeInfo = context.getAccessTypeInfo(
|
||||||
collectionElement.getQualifiedName()
|
collectionElementType.toString() );
|
||||||
.toString()
|
|
||||||
);
|
|
||||||
if ( accessTypeInfo == null ) {
|
if ( accessTypeInfo == null ) {
|
||||||
AccessType explicitAccessType = TypeUtils.determineAnnotationSpecifiedAccessType(
|
AccessType explicitAccessType = null;
|
||||||
|
if ( collectionElement != null ) {
|
||||||
|
explicitAccessType = TypeUtils.determineAnnotationSpecifiedAccessType(
|
||||||
collectionElement
|
collectionElement
|
||||||
);
|
);
|
||||||
|
}
|
||||||
accessTypeInfo = new AccessTypeInformation(
|
accessTypeInfo = new AccessTypeInformation(
|
||||||
collectionElement.getQualifiedName().toString(),
|
collectionElementType.toString(),
|
||||||
explicitAccessType,
|
explicitAccessType,
|
||||||
entity.getEntityAccessTypeInfo().getAccessType()
|
entity.getEntityAccessTypeInfo().getAccessType()
|
||||||
);
|
);
|
||||||
context.addAccessTypeInformation(
|
context.addAccessTypeInformation( collectionElementType.toString(), accessTypeInfo );
|
||||||
collectionElement.getQualifiedName().toString(), accessTypeInfo
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
accessTypeInfo.setDefaultAccessType( entity.getEntityAccessTypeInfo().getAccessType() );
|
accessTypeInfo.setDefaultAccessType( entity.getEntityAccessTypeInfo().getAccessType() );
|
||||||
|
|
|
@ -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.assertMapAttributesInMetaModelFor;
|
||||||
import static org.hibernate.jpamodelgen.test.util.TestUtil.assertMetamodelClassGeneratedFor;
|
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.assertNoSourceFileGeneratedFor;
|
||||||
|
import static org.hibernate.jpamodelgen.test.util.TestUtil.assertPresenceOfFieldInMetamodelFor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Hardy Ferentschik
|
* @author Hardy Ferentschik
|
||||||
|
@ -59,4 +60,14 @@ public class ElementCollectionTest extends CompilationTest {
|
||||||
Hostel.class, "cleaners", Room.class, Cleaner.class, "Wrong type in map attribute."
|
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."
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue