HibernateDomainExporter - issues with generic Map definitions inside component types #404

Closed
joelc opened this Issue Apr 25, 2013 · 5 comments

Comments

Projects
None yet
2 participants
@joelc

joelc commented Apr 25, 2013

When I set the HibernateDomainExporter loose with a domain class with this field:

    private Map<Integer, Chunk> chunks;

And this in the hbm.xml:

        <component name="fooFile" access="field">
            <map name="chunks" access="field" cascade="all">
                <key column="fooid" update="false" not-null="true" />
                <index type="int" column="CHUNKNUMBER" />
                <one-to-many class="foo.Chunk" />
            </map>

            <property name="deleted" access="field" />
        </component>

I get this exception:

Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
    at java.util.Arrays$ArrayList.get(Arrays.java:2866)
    at com.mysema.query.codegen.Property.getParameter(Property.java:135)
    at com.mysema.query.codegen.EntitySerializer.serializeProperties(EntitySerializer.java:784)
    at com.mysema.query.codegen.EntitySerializer.serialize(EntitySerializer.java:615)
    at com.mysema.query.jpa.codegen.HibernateDomainExporter.write(HibernateDomainExporter.java:517)

I believe this is because in HibernateDomainExporter (from 3.1.1) at line 377 you expect the field to have one generic type (the "componentType") only. For j.u.Map there are two!

I have fixed this locally by replacing the code:

                if (entityName != null) {
                    Type componentType = typeFactory.get(Class.forName(entityName));
                    propertyType = new SimpleType(propertyType, componentType);    
                } 

With:

                if (entityName != null) {
                    if (collection.isMap()) {
                        Type keyType = typeFactory.get(Class.forName(propertyType.getParameters().get(0).getFullName()));
                        Type valueType = typeFactory.get(Class.forName(entityName));
                        propertyType = new SimpleType(propertyType, keyType, valueType);
                    } else {
                        Type componentType = typeFactory.get(Class.forName(entityName));
                        propertyType = new SimpleType(propertyType, componentType);
                    }
                }

I suspect mine is a nastier hack than your choice of solution would be, but unfortunately I don't have much time left to look into what the more elegant solution is!

Thanks

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Apr 26, 2013

Member

Could you provide an examble Hibernate xml configuration document and the related classes for a test case?

Member

timowest commented Apr 26, 2013

Could you provide an examble Hibernate xml configuration document and the related classes for a test case?

timowest added a commit that referenced this issue Apr 29, 2013

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Apr 29, 2013

Member

For now the solution is based on your suggestion. But please provide a proper test case for this.

Member

timowest commented Apr 29, 2013

For now the solution is based on your suggestion. But please provide a proper test case for this.

@joelc

This comment has been minimized.

Show comment
Hide comment
@joelc

joelc Apr 29, 2013

Yes - apologies - I will do, just running on a real tight time constraint right now and isolating the specifics is going to take time away from my project.

Will provide reproducible test shortly...

joelc commented Apr 29, 2013

Yes - apologies - I will do, just running on a real tight time constraint right now and isolating the specifics is going to take time away from my project.

Will provide reproducible test shortly...

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest May 27, 2013

Member

Released in 3.2.0

Member

timowest commented May 27, 2013

Released in 3.2.0

@timowest timowest closed this May 27, 2013

@joelc

This comment has been minimized.

Show comment
Hide comment
@joelc

joelc Jun 11, 2013

Timo,

I apply this patch (https://gist.github.com/joeltgf/5754019) to the QUERYDSL_3_1_1 tag and the exception is thrown.

After you make the change as suggested above, the exception disappears.

Not the best test case on the planet I'm afraid, but it does go some way to prove the issue I raised. Better late than never...!

joelc commented Jun 11, 2013

Timo,

I apply this patch (https://gist.github.com/joeltgf/5754019) to the QUERYDSL_3_1_1 tag and the exception is thrown.

After you make the change as suggested above, the exception disappears.

Not the best test case on the planet I'm afraid, but it does go some way to prove the issue I raised. Better late than never...!

@timowest timowest added this to the 3.2.0 milestone Apr 14, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment