2017-10-08 68 views

回答

0

這個問題有點模糊,我不知道,如果你知道如何刪除與Hibernate OGM一個實體,它不工作(在這種情況下,發佈您的代碼示例,請),或者你不知道JPA如何工作。我會假設你不知道如何刪除實體並添加一些關於如何去做的例子。

使用會話:

try (Session session = openSession()) { 
    Transaction transaction = session.beginTransaction(); 
    Hypothesis entity = (Hypothesis) session.get(Hypothesis.class, hyp.getId()); 
    session.delete(entity); 
    transaction.commit(); 
} 

使用EntityManager(JPA):

final EntityManager em = emf.createEntityManager(); 
try { 
    em.getTransaction().begin(); 
    Poem poem = em.find(Poem.class, poem.getId()); 
    em.remove(poem); 
    em.getTransaction().commit(); 
} 
finally { 
    em.close(); 
} 

使用MonogDB CLI API:

try (OgmSession session = openSession()) { 
    Transaction transaction = session.beginTransaction(); 
    String nativeQuery = "db.Poem.remove({ '_id': { '$numberLong': '11' } })"; 
    Query query = session.createNativeQuery(nativeQuery).addEntity(Poem.class); 
    query.executeUpdate(); 
} 

關於更新,我會留待Hibernate ORM documentation。 如果這不能回答你的問題,請嘗試詳細說明。總是讚賞測試用例。