English 中文(简体)
实体管理小组
原标题:EntityManager Lookup on CMT

我怀疑有很长的时间,从来也没有找到答案,因此,我赞赏任何帮助或解释的国王......如果它只是一个概念错误......

我的环境是我使用CMT和Hibernate。 我可以把实体管理组织作为我的紧急司法委员会的资源,没有任何问题。 但是,由于我用传统的工厂模式对它进行即时处理,我不得不把它直接投放到我的农业部。

但我的问题是:我需要利用实体管理者,但不要想通过我一层的倒一切。 别无选择,我也许看不到解决办法。

Can I do some king of context lookup for this EntityManager? Or any other more elegant solution?

我提出了自己的解决办法,但这种解决办法不值得指责。

由于任何造错误都得到任何帮助和担忧,它不是我的母语。

最佳回答

即便在“JBNizet”的拥抱之后,我仍然很想知道如何使实体管理起来。 我在如何在J2EE/EJB环境中寻找实体管理者方面找到答案。

首先,你们需要用“@PersistentContext on the category scope of their EJB,以便为以后的看管工作打折扣,并确定“姓名”属性。 和:

@PersistenceContext(
name="myEntityManagerJNDIName",
unitName=InventoryManagement  // defined in a persistence.xml file
)
@Stateless
public class InventoryManagerBean implements InventoryManager { ... }

之后,你可以找到像这样的法典:

...
// obtain the initial JNDI context
Context initCtx = new InitialContext();
// perform JNDI lookup to obtain container-managed entity manager
javax.persistence.EntityManager entityManager = (javax.persistence.EntityManager) 
   initCtx.lookup("java:comp/env/myEntityManagerJNDIName");
...

这是我发现无注入实体管理者的方式。

问题回答

暂无回答




相关问题
Multiple Hibernate instances using C3P0

I am facing a weird problem and it seems to be c3p0 related. I am starting two instances of an app in the same java vm which interact with each other. After some operations "APPARENT DEADLOCK" ...

Hibernate vs Ibatis caching

We can speed up a hibernate app easyly with 2nd level cache using infinispan or ehcache/terracotta,... but ibatis only have a simple interface to implement for caching. And hibernate knows more ...

Using annotations to implement a static join in hibernate

I m relatively new to hibernate and was wondering if someone could help me out. While I have no issues implementing a normal join on multiple columns in hibernate using the @JoinColumns tag, I m ...

Hibernate query with fetch question

I have a 2 entities in a One-To-Many relationship: OfficeView.java: public class OfficeView implements java.io.Serializable { private Integer officeId; private String addr1; private ...

hibernate interceptors : afterTransactionCompletion

I wrote a Hibernate interceptor : public class MyInterceptor extends EmptyInterceptor { private boolean isCanal=false; public boolean onSave(Object entity, Serializable arg1, Object[] arg2, String[]...

How to prevent JPA from rolling back transaction?

Methods invoked: 1. Struts Action 2. Service class method (annotated by @Transactional) 3. Xfire webservice call Everything including struts (DelegatingActionProxy) and transactions is configured ...

Hibernate/GORM: collection was not processed by flush()

I have an integration test in my Grails application that fails when I try to save an entity of type Member invitingMember.save(flush: true) This raises the following exception org.hibernate....

Hibernate Criteria API equivalent for "elements()"

Is it possible to implement the following query using Criteria API? select order from ORDER as order,ITEM as item where item.itemID like ITM_01 and item in elements(order.items)

热门标签