gpt4 book ai didi

java - 在 EntityMode.DOM4J session 中使用条件时出现 Hibernate NullPointerException

转载 作者:行者123 更新时间:2023-12-02 05:10:36 25 4
gpt4 key购买 nike

如果我尝试使用以下代码,则会遇到空指针异常:

//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();

我收到以下异常:

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)

org.hibernate.type.EntityType 的第 520 行包含以下内容:

return factory.getIdentifierType( getAssociatedEntityName() );

看起来工厂对象是空的......为什么???

最佳答案

你能发布你的映射文件吗?还要验证映射文件是否具有节点和类型信息。此链接可能对您有帮助。

http://docs.jboss.org/hibernate/core/3.3/reference/en/html/xml.html

关于java - 在 EntityMode.DOM4J session 中使用条件时出现 Hibernate NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/969110/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com