开发者

Jpa Controllers in NetBeans 7

I used to work with NetBeans 6.9.1 and this worked just fine. Now I'm working on NetBeans 7 and what I'm trying to do is to create a JPA Controller from a Entity Class, which is pretty much a wizard, when I was done with the process and I tried to call the recently generated JPA Controller, I found this inside:

public ClientsJpaController(UserTransaction utx, EntityManagerFactory emf) {
        this.utx = utx;
        this.emf = emf;
    }

I did the same in NetBeans 6.9.1 and this is what I have:

public ClientsJpaController() {
        emf = Persistence.createEntityManagerFactory("WebServicesInvestigacion6PU");
    }

What I want to know is why they changed it, and what's the right way to code with this new approach. 开发者_C百科


I recently researched something similar because I became alarmed when I noticed each of my 12 (twelve) NetBeans 6.9.1 generated controllers (for JSE App) created an instance of the EntityManagerFactory (EMF) as the NetBeans 6.9.1 example code included in question body illustrates.

Everything I read indicates that the application should not (nor need to) create more than one factory largely due to cache and initialization issues.

The recommended practice I seen more frequently suggests wrapping the EMF in a singleton and exposing it through the static accessor. Use a thread safe singleton.

So then it makes sense that NetBeans 7 has an EMF parameter. It looks like the NB7 controller supports best practice.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜