Today I would like to put a link to an Adam Bien post: Why I Like EJB 3.0 And Really Like EJB 3.1, that is a summary of EJB3 benefits.
You can achieve the same with other technologies, but EJB3 offers you the whole pack.
Sunday, June 15, 2008
Why I like EJB3...
Wednesday, May 14, 2008
Using JPA in a web application
I usually work creating my entity data model classes using JPA and creating session beans (or stateless/web services beans) in an EJB module to acces this data. Later, I create a web/desktop application to access entities through the previous module.
But sometimes you need/want to do a more quickly/ugly job working with entities directly from your web application. For those (like me today ;)) I put here this link to a JEE5 blueprint named: Design Choices in a Web-only Application Using Java Persistence.
Among other things, It talks about using container or application managed entity managers.
Thursday, July 05, 2007
Closing JPA EntityManger in web applications
I want to note this post from my neighborhood JavaNotepad.
When working with resources it's always important to ensure they are closed when not longer needed.
Working with JPA there are two kind of resources we can take care of: EntityManager and transactions.
Read...
Tuesday, June 05, 2007
Extending the DataProvider API with VisualWebPack
Until the coming version of NetBeans+VisualWebPack arrive and we can bind a WebService or EJB to a table or other component, here is a little idea to know how to do it in a correct way.
First of all, here are a couple of blogs that can help us in our search:
http://blogs.sun.com/winston
http://jkook.blogspot.com
If the VWP components are enough for your application, I think VWP is a grat tool that helps you top spend much more less time to create an application. The separation of request, session and application beans, the set of components, drag&drop and binding component to data sources: like a DB table.
However, what happens when you want to bind a component to the result of a web service or EJB. For the moment, you can extend the DataProvider API and play requesting data on request or session bean.
ObjectListData Provider work around - Sample Project
Creator Tip: Work around for Object List Data Provider design time problem
Wednesday, April 11, 2007
Sorting and paging - Interaction between EJB3 and JSF
Remember my previous post (Looking for EJB3 and JSF integration with Sun webui-jsf) about interacting with the business layer (EJB3) from JSF (with NetBeans VisualWebPack).
Ok, here is a set of posts that shows the steps for a possible solution:
Sorting and Paging with EJB Alternatives
Paging and Sorting in ejb3 Analysis
Sorting and paging with EJB3.
Basically you need to create a web module class that implements the DataProvider interface and this class call the beans of your EJB3 module.
Be happy.
Tuesday, April 03, 2007
Looking for EJB3 and JSF integration with Sun webui-jsf
Ok, after a good job you good model business and model layer, that is, you have a set of amazing entities (using JPA) and a set of business objects (EJB session beans).
Now you want to make a beautiful presentation tier. You can immolate or make a precise job using servlets, JSP or by your hand JSF pages.
But no, you are pretty lazy and also you are saw some videos using the new NetBeans VisualWebPack and you want to try its visual component and its easy to use.
What?... you can bind components (tables, labels, text fiels, droplist, ...) to tables or SELECTions, but what about my business layer? what can I do with all my previous job?
I was looking for "binding ejb to jsf" and here are some interesting links which points to some blueprints solutions:
JSF + Session Facade + Entity Bean (EJB3)
JSF combined with EJB, how??
but finally I found (not that I want but at least):
Creator/Vsual Web Pack sources are available in Netbeans repository
It seems in NB 5.5 it is not possible bind an EJB3 to a JSF visual component, but it will be possible in NB6.
Visual Web Development in NetBeans
Visual Web Consumer of Enterprise Java Beans from Services Tab
Finally, I want to point to Project Woodstock: ...an Open Source library of JSF components that provide modern presentations, including the use of AJAX. And borrowed from here: Woodstock is a new Java.net open source project that provides an extensive set of JavaServer Faces (JSF) components for web application developers to build enterprise level applications, and can be fully drag-and-drop enabled within NetBeans 5.5 and its Visual Web Pack.
Monday, January 15, 2007
EJB3 and dependency injection
Mistakes are a way to learn if one has enough persistence to find the solution.
Recently, in my adventure with the EJB3 I learn bit more.
Suposse you have a session bean named A_Bean. Inside it you can use anotations like @Resource, @PersistenceContext, ...
Suposse you have another bean named B_Bean needed by A_Bean in some method. Also B_Bean can have it own @Resource and @PersistenceContext annotations.
To do that, you have to options:
- Create the B_Bean by your hand,
- Left the container create a B_Bean instance and inject it in your code.
@Stateless
public class A_BeanImpl implements A_Bean {
@PersistenceContext
private EntityManager em;
private B_Bean bbean;
public void foo() {
bbean = new B_BeanImlp();
bbena.foo();
}
}@Stateless
public class B_BeanImpl implements B_Bean {
@PersistenceContext
private EntityManager em;
public void foo() {
// Do something
}
}
Here, when the container instantiates an instance of our A_Bean, it is responsible to obtain a reference to an EntityManager and inject it.Later in the A_Bean.foo() methos we are creating by our hand an instance of B_Bean. This means the container hadn't had nothing to do with the instanciation and then, the B_Bean EntityManager reference is null, NULL !!!
The second method, let the container create the B_Bean instance is something like:
@Stateless
public class A_BeanImpl implements A_Bean {
@PersistenceContext
private EntityManager em;
@EJB
private B_Bean bbean;
public void foo() {
bbena.foo();
}
} @Stateless
public class B_BeanImpl implements B_Bean {
@PersistenceContext
private EntityManager em;
public void foo() {
// Do something
}
} Here, in the A_Bean.foo() method you can invoque a B_Bean method because the container was responsible to instantiate a B_Bean bean and inject it. Also, and the most important, the container has injected the EntityManager references into the B_Bean and they aren't null.
Thursday, November 23, 2006
Glassfish and socket problems
I was trying use gnu.hylafax libraries (a libraries that implement the HylaFAX protocol, similar to the FTP) to comunicate with a HylaFAX server.
I had created an EJB module with a class containig all the necessary code. I had been tested it in a simple java application and works fine, but when I put it into the EJB class, it fails. See the post at: Hylafax connection into an EJB module to see the error.
To resume the error was in the socket implementation. Looking for help I saw that many people has the same problem, and the solution was to do (see Unable to launch the Java AppServer or Timeout waiting for domain1 to start):
- cd
\domains\domain1 - edit config\domain.xml
- search for elements like
- add
-Dcom.sun.enterprise.server.ss.ASQuickStartup=false - save the file.
Friday, October 06, 2006
Glassfish and PostgreSQL problems
If you are working with Glassfish v1_ur1_b14, PostgreSQL and NetBeans 5.5 probably you had experienced some dificulties with entity class.
(1) you develop the code.
(2) you compile and build your code (an .ear or .war file)
(3) you can't deploy your application :(, Glassfish says you there is an error (with a null desciption) but if you chech your app with the verifier utility it is right.
Well, here are acouple of links describing the problem (related with the @GeneratedValue annotation) and describing a solution: