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.
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?
posted 6 years ago
I clicked on more details about the error, I see this:
I guess it has something to do with the arquillian.
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!
posted 6 years ago
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:
posted 6 years ago
Does anyone think we need a database called chapter2 in order to make the code run?
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.
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.
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
2. JNDI lookup?
posted 6 years ago
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."
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