[hibernate-issues] [Hibernate-JIRA] Updated: (METAGEN-56) Missing Singular attribute in import when merging attributes
Hardy Ferentschik (JIRA)
noreply at atlassian.com
Mon Jan 16 08:34:13 EST 2012
[ http://opensource.atlassian.com/projects/hibernate/browse/METAGEN-56?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Hardy Ferentschik updated METAGEN-56:
-------------------------------------
Fix Version/s: (was: 1.2.next)
> Missing Singular attribute in import when merging attributes
> ------------------------------------------------------------
>
> Key: METAGEN-56
> URL: http://opensource.atlassian.com/projects/hibernate/browse/METAGEN-56
> Project: Hibernate Metamodel Generator
> Issue Type: Bug
> Components: processor
> Affects Versions: 1.1.1.Final
> Environment: maven 3.0.2
> Java: java version "1.6.0_22", Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
> Uname: Linux xxx 2.6.32-28-generic-pae #55-Ubuntu SMP Mon Jan 10 22:34:08 UTC 2011 i686 GNU/Linux
> Reporter: Martijn Blankestijn
> Assignee: Hardy Ferentschik
> Attachments: 0001-Missing-SingularAttribute-import-with-mixed-xml-and-.patch, 0002-METAGEN-56-Wrong-implementation-attribute-returned-M.patch, surefire-reports.tar.gz
>
>
> I have failing testcases due to a missing import in the Generated ZeroCoordinates_.java.
> My analysis:
> The import "import javax.persistence.metamodel.SingularAttribute;" is not added to the file ZeroCoordinates_.java and will not compile due to this missing dependency.
> It is a mixed configuration: so in the class JPAMetaModelEntityProcessor (line 237) the call is made to
> metaEntity.mergeInMembers( alreadyExistingMetaEntity.getMembers() );
> This basically means that the attributes of the already existing XML MetaEntity are placed in the attributesMap of the AnnotationMetaEntity.
> {code}
> public void mergeInMembers(Collection<MetaAttribute> attributes) {
> for ( MetaAttribute attribute : attributes ) {
> members.put( attribute.getPropertyName(), attribute );
> }
> }
> {code}
> This means that the AnnotationEmbeddable has a Context, but the members (the merged in Xml-attributes) have a different context. (Do not understand why there are two contexts, can you enlighten me?)
> In the ClassWriter line 107:
> {code}
> for ( MetaAttribute metaMember : members ) {
> pw.println( " " + metaMember.getDeclarationString() );
> }
> {code}
> the declaration string is printed. As the attributes are XMLMetaAttribute, their implementation of the getDeclarationString is
> {code}
> return "public static volatile " + hostingEntity.importType( getMetaType() )
> + "<" + hostingEntity.importType( hostingEntity.getQualifiedName() )
> + ", " + hostingEntity.importType( getTypeDeclaration() )
> + "> " + getPropertyName() + ";";
> {code}
> The hosting entity of the attribute is still the XmlMetaEmbeddable and when the importType is added, it is added to the wrong context (the context of the XMLMetaEmbeddable and NOT the AnnotationMetaEmbeddable).
> Possible solution is to change the parent or create a new merged attribute (not ugly like I do below ;-))
> {code}
> MetaAttribute mergedAttribute = new XmlMetaSingleAttribute(this, attribute.getPropertyName(), attribute.getMetaType());
> members.put( attribute.getPropertyName(), mergedAttribute );
> {code}
> This resolves the problem with the missing import, but if it is better to have a single context for both annotation and xml elements this might be a cleaner solution. Attached is the 'ugly' solution, but this leaves two failing testcases:
> {noformat}
> testAccessTypeForXmlConfiguredEmbeddables(org.hibernate.jpamodelgen.test.mixedmode.MixedConfigurationTest)
> testMixedConfiguration(org.hibernate.jpamodelgen.test.mixedmode.MixedConfigurationTest)
> {noformat}
> The testMixedConfiguration could be a problem that the supplied solution is not yet the definitive answer ;-(:
> {noformat}
> =======================================================
> Types do not match: Wrong meta model type expected:<class org.hibernate.jpamodelgen.test.mixedmode.RentalCompany> but was:<interface javax.persistence.metamodel.SingularAttribute>
> org.testng.Assert.fail(Assert.java:84)
> at org.testng.Assert.failNotEquals(Assert.java:438)
> at org.testng.Assert.assertEquals(Assert.java:108)
> at org.hibernate.jpamodelgen.test.util.TestUtil.assertAttributeTypeInMetaModelFor(TestUtil.java:176)
> at org.hibernate.jpamodelgen.test.mixedmode.MixedConfigurationTest.testMixedConfiguration(MixedConfigurationTest.java:68)
> 30 lines not shown
> =======================================================
> {noformat}
> The testAccessTypeForXmlConfiguredEmbbedables seems unreleated:
> {code}
> assertAbsenceOfFieldInMetamodelFor(
> ZeroCoordinates.class,
> "longitude",
> "Field access should be used, but ZeroCoordinates does not define fields"
> );
> assertAbsenceOfFieldInMetamodelFor(
> ZeroCoordinates.class,
> "latitude",
> "Field access should be used, but ZeroCoordinates does not define fields"
> );
> {code}
> as I am not completely sure that the asserts are correct. The access type of embeddables dependends on the enclosing entity, so ain't it true that the field AND properties should be generated?
> Regards,
> Martijn
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list