我正在使用Hibernate OGM 5.0.0.Final与mongodb 3.2使用Spring 4,WildFly 10
以下代码适用于Object []
List<Object[]> result = em.createNativeQuery("{ \"id\": \"1\" }").getResultList();
但是如果我使用实体来查询这个
List<Survey> result = em.createNativeQuery("{ \"id\": \"1\"}", Survey.class).getResultList();
它会抛出
ERROR [stderr] (default task-2) java.lang.NoSuchMethodError: org.hibernate.engine.internal.TwoPhaseLoad.addUninitializedEntity(Lorg/hibernate/engine/spi/EntityKey;Ljava/lang/Object;Lorg/hibernate/persister/entity/EntityPersister;Lorg/hibernate/LockMode;ZLorg/hibernate/engine/spi/SessionImplementor;)V at org.hibernate.ogm.loader.impl.OgmLoader.loadFromResultSet(OgmLoader.java:1143) at org.hibernate.ogm.loader.impl.OgmLoader.instanceNotYetLoaded(OgmLoader.java:1065) at org.hibernate.ogm.loader.impl.OgmLoader.getRow(OgmLoader.java:959) at org.hibernate.ogm.loader.impl.OgmLoader.getRowFromResultSet(OgmLoader.java:498) at org.hibernate.ogm.loader.impl.OgmLoader.doQuery(OgmLoader.java:373) at org.hibernate.ogm.loader.impl.OgmLoader.doQueryAndInitializeNonLazyCollections(OgmLoader.java:283) at org.hibernate.ogm.loader.impl.OgmLoader.loadEntity(OgmLoader.java:201) at org.hibernate.ogm.loader.impl.OgmLoader.load(OgmLoader.java:157) at org.hibernate.ogm.loader.impl.OgmLoader.load(OgmLoader.java:149) at org.hibernate.ogm.loader.entity.impl.DynamicBatchingEntityLoaderBuilder$DynamicBatchingEntityLoader.load(DynamicBatchingEntityLoaderBuilder.java:116) at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3991) at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:508) at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:478) at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:219) at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:262) at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:121) at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:89) at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1142) at org.hibernate.internal.SessionImpl.access$2600(SessionImpl.java:167) at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.doLoad(SessionImpl.java:2762) at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.load(SessionImpl.java:2741) at org.hibernate.internal.SessionImpl.get(SessionImpl.java:978) at org.hibernate.engine.spi.SessionDelegatorBaseImpl.get(SessionDelegatorBaseImpl.java:629) at org.hibernate.jpa.spi.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:1075) at org.hibernate.jpa.spi.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:1033) at org.hibernate.ogm.jpa.impl.OgmEntityManager.find(OgmEntityManager.java:97)
有谁知道如何解决这个问题?
这是我的一些代码
Survey.java
@Entity
public class Survey {
@Id
private String id;
private String created_by;
private String desc;
//getter,setter
}
的persistence.xml
<?xml version="1.0"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="mongodb_persistence"
transaction-type="JTA">
<!-- Use Hibernate OGM provider: configuration will be transparent -->
<provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider>
<class>com.ogm.entity.Survey</class>
<properties>
<property name="hibernate.transaction.jta.platform" value="JBossAS" />
<property name="hibernate.ogm.datastore.provider" value="mongodb" />
<property name="hibernate.ogm.datastore.host" value="localhost" />
<property name="hibernate.ogm.datastore.port" value="27017" />
<property name="hibernate.ogm.datastore.database" value="testdb" />
<property name="hibernate.ogm.neo4j.database_path" value="target/test_data_dir" />
</properties>
</persistence-unit>
</persistence>