mnimer / dphibernate

Automatically exported from code.google.com/p/dphibernate
0 stars 0 forks source link

When using InheritenceStrategy & DiscriminatorColumn, wrong type is returned from a collection #51

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Given the following:
{{{
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="postType", 
discriminatorType=DiscriminatorType.STRING)
public class Post {}

@DiscriminatorValue(value = PostType.BUG)
public class BugReport extends Post {}

public class Milestone {
    List<Post> posts;
}
}}}

When the posts property of Milestone is lazy loaded, the returned collection 
will be a collection of proxies for the class Post.

This is incorrect.  In theory, any subclass of Post could exist in the 
collection, as determined by the DiscriminatorValue.

Essentially, in HibernateSerializer, we determine the type of the proxy to 
return for the entire collection by the elementType in the 
`AbstractCollectionPersister`:

{{{
            if (persister instanceof AbstractCollectionPersister)
            {
                AbstractCollectionPersister absPersister = (AbstractCollectionPersister) persister;
                String className = absPersister.getElementType().getName();

                if (session instanceof Session)
                {
                    List pkIds = getPkIds(session, absPersister, collection);
}}}

Not sure what the solution to this problem is, without a tonne of nasty 
reflection.

Original issue reported on code.google.com by martypit...@gtempaccount.com on 16 Sep 2010 at 6:08

GoogleCodeExporter commented 9 years ago
Fixed in r211.

Will be available in 2.0RC-2

Original comment by martypit...@gtempaccount.com on 17 Sep 2010 at 1:22