[hibernate-issues] [Hibernate-JIRA] Created: (HHH-4018) ClassCastException with EntityMode.DOM4J in case of object as index

Renat Valeev (JIRA) noreply at atlassian.com
Mon Jul 6 08:37:12 EDT 2009


ClassCastException with EntityMode.DOM4J in case of object as index
-------------------------------------------------------------------

                 Key: HHH-4018
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4018
             Project: Hibernate Core
          Issue Type: Bug
         Environment: Hibernate 3.2.6.ga, HSQLDB
            Reporter: Renat Valeev


public class TestA {
    private Map testMap = new HashMap<TestIndex, TestElement>();
    private int id;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }
    
    public Map getTestMap() {
        return testMap;
    }

    public void setTestMap(Map testMap) {
        this.testMap = testMap;
    }
}

public class TestIndex {
    private int id;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }
}

public class TestElement {
    private int id;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }
}


--------------
Mappings
--------------

<hibernate-mapping default-lazy="true">
    <class name="TestA" node="TestA">
        <id name="id" type="integer" column="id" node="@id">
            <generator class="increment" />
        </id>
        <map name="testMap" cascade="all" embed-xml="true" node="testMap">
            <key column="parent_id" />
            <map-key-many-to-many column="index_id" class="TestIndex"/>
            <many-to-many column="element_id" class="TestElement" embed-xml="true" node="test_element" />
        </map>
    </class>
    <class name="TestIndex" node="TestIndex">
        <id name="id" type="integer" column="id" node="@id">
            <generator class="increment" />
        </id>
    </class>
    <class name="TestElement" node="TestElement">
        <id name="id" type="integer" column="id" node="@id">
            <generator class="increment" />
        </id>
    </class>
</hibernate-mapping>

--------------
Test class
--------------

 public class test extends AbstractTransactionalJUnit38SpringContextTests{
    @Autowired
    private SessionFactory _sessionFactory;
    
    @Test
    @Transactional
    public void testTest(){
        Session dom4jSession = _sessionFactory.getCurrentSession().getSession(EntityMode.DOM4J);
        List result = dom4jSession.createCriteria(TestA.class).list();                          // EXCEPTION RAISES HERE
        for (int i = 0; i < result.size(); i++) {
            Element node = (Element) result.get(i);
            System.out.println(node);
        }
    }
    
    @Transactional
    @Override
    public void setUp() throws Exception{
        TestIndex ti = new TestIndex();
        TestElement te = new TestElement();
        _sessionFactory.getCurrentSession().saveOrUpdate(ti);
        _sessionFactory.getCurrentSession().saveOrUpdate(te);
        TestA t = new TestA();
        HashMap<TestIndex,TestElement> hm = new HashMap<TestIndex,TestElement>();
        hm.put(ti, te);
        t.setTestMap(hm);
        _sessionFactory.getCurrentSession().saveOrUpdate(t);
        _sessionFactory.getCurrentSession().flush();
    }

}

java.lang.ClassCastException: org.hibernate.type.ManyToOneType cannot be cast to org.hibernate.type.NullableType
        at org.hibernate.collection.PersistentIndexedElementHolder.readFrom(PersistentIndexedElementHolder.java:144)
        at org.hibernate.loader.Loader.readCollectionElement(Loader.java:1008)
        at org.hibernate.loader.Loader.readCollectionElements(Loader.java:646)
        at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:591)
        at org.hibernate.loader.Loader.doQuery(Loader.java:701)
        at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
        at org.hibernate.loader.Loader.loadCollection(Loader.java:1994)
        at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:36)
        at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:565)
        at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:63)
        at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1716)
        at org.hibernate.type.CollectionType.getCollection(CollectionType.java:613)
        at org.hibernate.type.CollectionType.resolveKey(CollectionType.java:408)
        at org.hibernate.type.CollectionType.resolve(CollectionType.java:402)
        at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:120)
        at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:854)
        at org.hibernate.loader.Loader.doQuery(Loader.java:729)
        at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
        at org.hibernate.loader.Loader.doList(Loader.java:2213)
        at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
        at org.hibernate.loader.Loader.list(Loader.java:2099)
        at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
        at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1569)
        at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
        at testTest(test.java:34)


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list