Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
joelc opened this issue Apr 25, 2013 · 5 comments
Closed
Milestone

Comments

@joelc
Copy link

@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
Copy link
Member

@timowest 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
Copy link
Member

@timowest timowest commented Apr 29, 2013

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

@joelc
Copy link
Author

@joelc 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
Copy link
Member

@timowest timowest commented May 27, 2013

Released in 3.2.0

@timowest timowest closed this May 27, 2013
@joelc
Copy link
Author

@joelc 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
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants