Hibernate OGMNoSQL的持久层框架
Hibernate 团队对外宣布了一个新的家族成员,Hibernate OGM, OGM 是 Object Grid Mapping的缩写,它的目标是试图使用 JPA 来操作 NoSQL数据库。
示例代码:
@PersistenceContext EntityManager em; // the transaction boundary is really here to express the flush time @Transactional public void createSomeUser() { Employer redHat = em.createQuery("from Employer e where e.name = :name") .setParamater("name", "Red Hat") .getSingleResult(); User emmanuel = new User("Emmanuel", "Bernard"); user.setTwitterHandle("emmanuelbernard"); user.setEmployer(redHat); em.persist(user); } //查询 // native query using CypherQLString query = "MATCH ( n:Poem { name:'Portia', author:'Oscar Wilde' } ) RETURN n"; Poem poem = (Poem) em.createNativeQuery( query, Poem.class ).getSingleResult();
评论