views:

485

answers:

0

Hi, I'm running into a null pointer exception if I try to use the following code:

//Spring JPA entityManager allow us to retriver the underlying session.
org.hibernate.Session session = (org.hibernate.Session)entityManager.getDelegate();
org.hibernate.Session dom4jSession = session.getSession(org.hibernate.EntityMode.DOM4J);

org.hibernate.Criteria c = session.createCriteria(User.class);
c.list();

I get the following exception:

java.lang.NullPointerException
    at org.hibernate.type.EntityType.getIdentifierType(EntityType.java:520)
    at org.hibernate.type.EntityType.setToXMLNode(EntityType.java:377)
    at org.hibernate.property.Dom4jAccessor$ElementSetter.set(Dom4jAccessor.java:333)
    at org.hibernate.tuple.component.AbstractComponentTuplizer.setPropertyValues(AbstractComponentTuplizer.java:104)
    at org.hibernate.type.ComponentType.setPropertyValues(ComponentType.java:381)
    at org.hibernate.type.ComponentType.resolve(ComponentType.java:609)
    at org.hibernate.type.ComponentType.nullSafeGet(ComponentType.java:298)
    at org.hibernate.persister.collection.AbstractCollectionPersister.readElement(AbstractCollectionPersister.java:725)
    at org.hibernate.collection.PersistentElementHolder.readFrom(PersistentElementHolder.java:125)
    at org.hibernate.loader.Loader.readCollectionElement(Loader.java:1031)
    at org.hibernate.loader.Loader.readCollectionElements(Loader.java:669)
    at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:614)
    at org.hibernate.loader.Loader.doQuery(Loader.java:724)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
    at org.hibernate.loader.Loader.loadCollection(Loader.java:2015)
    at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:59)
    at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:587)
    at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:83)
    at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1743)
    at org.hibernate.type.CollectionType.getCollection(CollectionType.java:646)
    at org.hibernate.type.CollectionType.resolveKey(CollectionType.java:430)
    at org.hibernate.type.CollectionType.resolve(CollectionType.java:424)
    at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:139)
    at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:877)
    at org.hibernate.loader.Loader.doQuery(Loader.java:752)

The line 520 of org.hibernate.type.EntityType contains the following:

return factory.getIdentifierType( getAssociatedEntityName() );

It seems the factory object is null.... Why???