File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes EJB 3 in Action (2nd edition) Chapter 2 does not run Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB 3 in Action (2nd edition) Chapter 2 does not run" Watch "EJB 3 in Action (2nd edition) Chapter 2 does not run" New topic
Forums: Glassfish EJB and other Java EE Technologies
Author

EJB 3 in Action (2nd edition) Chapter 2 does not run

Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 742
Hi, everyone.
Has anyone cleaned and built chapter 2:ActionBazaar from EJB 3 in Action (2nd edition) ?
I got this error when I do clean and build in Netbean :

However in the src/test/resources/test-persistence.xml, the data source jdbc/chapter2 is defined :

In src/test/resources/domain.xml, there is jndi-name="jdbc/chapter2":


From the Manning forums, some people ran into the same issues at https://www.manning-sandbox.com/thread.jspa?threadID=67353&tstart=0

Any comments?
Ron McLeod
Ranch Hand

Joined: Feb 12, 2013
Posts: 294
    
    5

This is just a guess - JNDI name jdbc/chapter2 is not portable, and may not work in all JEE environments. Try replacing jdbc/chapter2 with java:app/jdbc/chapter2 in both xml files.
Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 742
Here is what I have in the sample code:
In src/main/resources, there is a META-INF folder, inside it, there is a persistence.xml:


In src/test/resources, there is a domain.xml file:


In src/test/resources/test-persistence.xml:


The test code provided in the book is :


I tried to run this test by doing "clean and build" in Netbean. But I got this time time:
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10068
    
163


In src/test/resources, there is a domain.xml file:


That looks more like a GlassFish server specific file and I am not sure how having that file placed in src/test/resources is going to force GlassFish to deploy the contents of that file (in this case the datasource).

Perhaps there's an additional step you need to follow to use that file and deploy it to GlassFish to make the datasource available?

I'm adding this thread to the GlassFish forum too. Maybe someone there knows about this.

[My Blog] [JavaRanch Journal]
Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 742
Thanks Pai.
I download the chapter 2 sample code (chapter2:ActionBazaar) from the Manning Publishing Co. And I opened it in Netbean. Before I deploy it, I right click on the project and select "clean and build" in Netbean. Then, I got the above error.
Does it related to the Glassfish ? Or does it related to some configuration in the xml files?

Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 742
I clicked on more details about the error, I see this:


and


I guess it has something to do with the arquillian.
Bell Katapa
Ranch Hand

Joined: Jan 06, 2012
Posts: 44

Hello Himai,

Just seen your post. I have not looked at EJB 3 in action 2nd edition yet. However try defining your own datasource from glassfish admin console and replace all occurrences of "jdbc/chapter2" with your own jndi name in the source as well as xml files. If you're using jndi lookup to acquire the datasource try first using the portable global jndi name. Also ensure the xml files are in the folder META-INF on the root of the class files. If your classes are running just as POJOs (outside the container/glassfish), you need to make available in your classpath some jar files from the glassfish installation folder, not sure which ones but the glassfish forum will yield more help. Also attempt to use the default persistence provider that comes with glassfish (Eclipselink) instead of the Hibernate as presently specified in your persistence.xml (unless you have available in your classpath the hibernate provider).

Hope this can help you towards working code!
Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 742
Hi, Bell. Thanks for your reply.

1. Do we need to change jdbc/chapter to something else?
2. The persistence.xml is provided as this:


3. The test-persistence.xml is provided as this :



4. The domain.xml is provided :



5. I launched Glassfish console. From there , I added a JDBC Connection Pool, Chapter2Pool with those property name and value provided in the domain.xml

6. From the Glassfish console, I added a JDBC resource jdbc/chapter2 as defined in jndi-name =jdbc/chapter2

7.I saved all the configuration and restarted Glassfish.

8. I run chapter 2 ActionBazaar again.

9. But I still get the same error:

Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 742
Does anyone think we need a database called chapter2 in order to make the code run?
Bell Katapa
Ranch Hand

Joined: Jan 06, 2012
Posts: 44

Hello Himai,

I downloaded the code from EJB3 in action 2nd edition and looked at it. I understand your goal is to learn and certify for EJB3. I think this edition wonders far from the core concern of introducing EJB3 as a technology to a new entrant. It cramps CDI, JPA, JSF and test frameworks into the example code, and it's just chapter 2?? These technologies could easily fill up respective books of 500 pages each, and they are not even on the exam.
EJB3 is a business tier technology accessible from many presentation layer technologies including those that are web service-based. I think it would be more natural and simpler if invocation of EJB components were demonstrated from Java SE and servlets (chances are high that someone new to EJB is already farmiliar with these two approaches). JSP, JSF, web services e.t.c may optionally be shown as presentation layer alternatives. The aim should be not to distract from the primary focus of learning the core technology, EJB3 in this case.

Regards,

Bell.
Bell Katapa
Ranch Hand

Joined: Jan 06, 2012
Posts: 44

No you don't need to name your database "chapter2". Also you don't need the database to learn EJB3. JPA books/certification will serve you well for persistence needs. Try the book "EJB3.1 Cookbook" by Richard M. Reese published by packt since you are already adept to using netbeans+glassfish. It does a great job introducing EJB3 with as little distraction as possible.
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1012
    
    5



Doesn't this line imply that a Derby database instance is running locally on port 1527?
Bell Katapa
Ranch Hand

Joined: Jan 06, 2012
Posts: 44

I wonder if a NamingException could occur in instances where db connectivity is a problem. It appears there is more of JNDI resolution problem. However you could be right James. Himai why don't you try the "Ping" button from the glassfish admin console and test datasource injection of the name "jdbc/chapter2" from a simple servlet using 1st:
1. @Resource annotation
and secondly
2. JNDI lookup?
Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 742
Thanks for James and Bell's replies.
First of all, I can't even build chapter 2 ActionBazaar. Because the NameNotFound exception is thrown when I hit "clean and build" or "build with dependency".

Secondly, I created Chapter2Pool under JDBC Connection Pool from Glassfish admin console. I ping it. It says
"
Ping Connection Pool failed for Chapter2Pool. Connection could not be allocated because: The connection was refused because the database chapter2 was not found. Please check the server.log for more details."

Bell Katapa
Ranch Hand

Joined: Jan 06, 2012
Posts: 44

I was able to successfully build and deploy the example project from chapter 2 by
1. creating a new war project (with support for jsf)
2. creating packages to mirror those from the downloaded project
3. copying source files to mirrored location in new project
4. replace occurrences of "jdbc/chapter2" with a jndi name representation of a working datasource connection
5. replace hibernate persistence provider with eclipse in the persistence.xml file

I omitted all the the test files though from the process.

There were no errors on deployment. However when i tried to load the home page (i.e. http://localhost:8080/ActionBazaar) i was getting '404 - page not found error'. Same error even with /index.jsf is appended.
A section of the glassfish's server.txt log confirms the successful deployment

"[2014-06-16T00:36:34.389+0200] [glassfish 4.0] [INFO] [ejb.portable_jndi_names] [javax.enterprise.system.container.ejb.com.sun.ejb.containers] [tid: _ThreadID=145 _ThreadName=AutoDeployer] [timeMillis: 1402871794389] [levelValue: 800] [[
EJB5181:Portable JNDI names for EJB OrderProcessorBean: [java:global/example/OrderProcessorBean, java:global/example/OrderProcessorBean!com.actionbazaar.buslogic.OrderProcessor]]]

[2014-06-16T00:36:34.436+0200] [glassfish 4.0] [INFO] [ejb.portable_jndi_names] [javax.enterprise.system.container.ejb.com.sun.ejb.containers] [tid: _ThreadID=145 _ThreadName=AutoDeployer] [timeMillis: 1402871794436] [levelValue: 800] [[
EJB5181:Portable JNDI names for EJB ItemServiceBean: [java:global/example/ItemServiceBean!com.actionbazaar.buslogic.ItemService, java:global/example/ItemServiceBean]]]

[2014-06-16T00:36:34.467+0200] [glassfish 4.0] [INFO] [ejb.portable_jndi_names] [javax.enterprise.system.container.ejb.com.sun.ejb.containers] [tid: _ThreadID=145 _ThreadName=AutoDeployer] [timeMillis: 1402871794467] [levelValue: 800] [[
EJB5181:Portable JNDI names for EJB UserServiceBean: [java:global/example/UserServiceBean, java:global/example/UserServiceBean!com.actionbazaar.buslogic.UserService]]]

[2014-06-16T00:36:35.513+0200] [glassfish 4.0] [INFO] [jsf.config.listener.version] [javax.enterprise.resource.webcontainer.jsf.config] [tid: _ThreadID=145 _ThreadName=AutoDeployer] [timeMillis: 1402871795513] [levelValue: 800] [[
Initializing Mojarra 2.2.0 ( 20130502-2118 https://svn.java.net/svn/mojarra~svn/tags/2.2.0@11930) for context '/ActionBazaar']]

[2014-06-16T00:36:38.381+0200] [glassfish 4.0] [INFO] [AS-WEB-GLUE-00172] [javax.enterprise.web] [tid: _ThreadID=145 _ThreadName=AutoDeployer] [timeMillis: 1402871798381] [levelValue: 800] [[
Loading application [example] at [/ActionBazaar]]]

[2014-06-16T00:36:39.910+0200] [glassfish 4.0] [INFO] [] [javax.enterprise.system.core] [tid: _ThreadID=145 _ThreadName=AutoDeployer] [timeMillis: 1402871799910] [levelValue: 800] [[
example was successfully deployed in 52,929 milliseconds.]]
"
A. Aka
Ranch Hand

Joined: Sep 08, 2012
Posts: 45
hi,

were you able to solve this issue ? I have the same problem and it is kind frustrating

Cheers,
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EJB 3 in Action (2nd edition) Chapter 2 does not run