Solved

Is it possible to distribute/share a persistence unit to multiple EJB modules containing entities?

Posted on 2011-09-27
6
263 Views
Last Modified: 2012-05-12
Hi Experts.

In a J2EE 6 EAR, I would like to know if there is any means to distribute/reuse a persistence unit through multiple EJB modules.

As I understand, the unit seems limited to a single module. But I just want to check with you.
And if it is the case, does anyone have recommandation about how it should be implemented? Should entities always be packed in a single module?

Thanks for any lead.
0
Comment
Question by:__geof__
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 20

Expert Comment

by:a_b
ID: 36813680
Yes it possible. You will need to pass the persistence unit around via a utility EJB.
0
 
LVL 6

Author Comment

by:__geof__
ID: 36813963
Thanks a_b.

If I understand you correctly and take a starting point in an EAR, I must add my utility EJB in the lib?

Is it also possible that Netbeans doesn't recognize this setup?
0
 
LVL 20

Accepted Solution

by:
a_b earned 500 total points
ID: 36813974
Not necessarily in the lib. What you could do is create one EJB in your ear that has the persistence unit and then pass that ejb to other ejbs to use the persistence unit.
Eg.
@Stateles....
public class EJBUtils
{
      @PersistenceUnit(...)
      EntityManager em;

       Create getters and setters
}

@Stateless
public class EmployeeBean
{

    @EJB
    EJBUtilsLocal ejbUtils;

    //Now via ejbUtils you can get a a hold of the entity manager you created.

}

0
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
LVL 6

Author Comment

by:__geof__
ID: 36814010
Just to be precise, I'm talking about Entity Beans (with annotation mapping to the database).
0
 
LVL 20

Assisted Solution

by:a_b
a_b earned 500 total points
ID: 36863619
You can do that. Use a common EntityManager and refernece the beans from the stateless session beans.
0
 
LVL 6

Author Comment

by:__geof__
ID: 36889999
OK . Thanks. I'll check it out and come back to you.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to convert from xls to xlsx using java 7 144
String array comparison 4 55
eclipse console opening separately 2 46
Delete .class files at every compile 4 55
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question