首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Hibernate-OGM mongodb,不能删除实体-分离

Hibernate-OGM mongodb,不能删除实体-分离
EN

Stack Overflow用户
提问于 2014-07-10 02:05:08
回答 1查看 589关注 0票数 0

所以我尝试在MongoDB中使用Hibernate OGM (4.1.0.Beta 4),现在我遇到了这个问题,这让我很困惑,所以我得到了我创建的实体的列表,然后我尝试遍历这个列表并删除每个列表--但是当我尝试得到下面的异常“删除一个分离的实例”时,我假设我忽略了持久性设置中的一些东西。

上下文路径:/TestApp路径:/rest路径信息:/删除请查询字符串:空堆栈跟踪org.jboss.resteasy.spi.UnhandledException: javax.ejb.EJBException: java.lang.IllegalArgumentException:删除独立实例org.jboss.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:76) org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:212) org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:149)org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:372) org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:179) org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220) org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56) org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51) javax.servlet.http.HttpServlet.service(HttpServlet.java:790) io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85) io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61) io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78) io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.io.undertow.security.handlers.AuthenticationCallHandler.handleRequest(AuthenticationCallHandler.java:52) io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45) io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:61) io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70) io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76) io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61) io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:240) io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:227) io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:73)io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:146) io.undertow.server.Connectors.executeRootHandler(Connectors.java:168) io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:687) java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) java.lang.Thread.run(未知源)

这是从我的休息服务处打来的

代码语言:javascript
复制
@Path("/")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@RequestScoped
public class TestService {

@Inject
    private TestRepository testRepo;

    @GET
    @Path("/deleteallplease")
    public String deleteAllTests(){

        for( TestEntity rp : testRepo.findAll() ){
            testRepo.delete( rp );
        }

        return "done done done";
    }


}

TestRepo类

代码语言:javascript
复制
@Stateless
@LocalBean
public class TestRepository {

@Inject
private EntityManager em;

@Inject 
private Logger log;

public List<TestEntity> findAll() {
    return em.createQuery("FROM TestEntity", TestEntity.class).getResultList();
}

persistence.xml

代码语言:javascript
复制
<persistence version="2.0"
         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">

<persistence-unit name="primary" >
    <provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider>
    <class>com.test.TestEntity</class>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
        <property name="hibernate.ogm.datastore.provider" value="mongodb"/>
        <property name="hibernate.ogm.datastore.database" value="db"/>
        <property name="hibernate.ogm.datastore.host" value="127.0.0.1"/>
        <property name="hibernate.ogm.datastore.port" value="59541"/>
        <property name="hibernate.ogm.datastore.username" value="user"/>
        <property name="hibernate.ogm.datastore.password" value="password"/>
        <property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform" />
    </properties>
</persistence-unit>

</persistence>

我想我最困惑的是使用deleteAllTests()来获取实体列表,然后尝试删除它们,但它们已经分离了吗?因此,我显然也错过了一些基本的东西,我怀疑它的芒果- ogm和JTA玩得不好,因为芒果不是交易,但我想ogm会抽象化对我。

EN

回答 1

Stack Overflow用户

发布于 2015-06-26 13:32:11

没有看到delete()方法,但我认为您正在使用em.remove()删除实体。

您可以尝试使用em.remove(实体)删除。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24666385

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档