• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Bartender
Posts: 2418
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Marshal
Posts: 4501
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Bartender
Posts: 2418
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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.
 
Himai Minh
Bartender
Posts: 2418
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Bartender
Posts: 2418
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I clicked on more details about the error, I see this:


and


I guess it has something to do with the arquillian.
 
Ranch Hand
Posts: 58
Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Bartender
Posts: 2418
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Bartender
Posts: 2418
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does anyone think we need a database called chapter2 in order to make the code run?
 
Bell Katapa
Ranch Hand
Posts: 58
Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 58
Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 1051
5
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Doesn't this line imply that a Derby database instance is running locally on port 1527?
 
Bell Katapa
Ranch Hand
Posts: 58
Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Bartender
Posts: 2418
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 58
Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.]]
"
 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

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

Cheers,
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I solved it doing an upgrade to arquillian:

pom.xml
=====


<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-glassfish-embedded-3.1</artifactId>
<version>1.0.0.CR3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.main.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
<version>3.1.2</version>
<scope>provided</scope>
</dependency>


I delete domain.xml and change arquillian.xml


Arquillian.xml
=========

<?xml version="1.0" encoding="UTF-8"?>
<arquillian xmlns="http://jboss.org/schema/arquillian"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://jboss.org/schema/arquillian
http://jboss.org/schema/arquillian/arquillian_1_0.xsd">

<container qualifier="glassfish-embedded" default="true">
<configuration>
<property name="resourcesXml">
src/test/resources/glassfish-resources.xml
</property>
</configuration>
</container>


</arquillian>


glassfish-resources.xml
===============

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC
"-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN"
"http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
<jdbc-resource pool-name="ArquillianEmbeddedDerbyPool"
jndi-name="jdbc/chapter2"/>
<jdbc-connection-pool name="ArquillianEmbeddedDerbyPool"
res-type="javax.sql.DataSource"
datasource-classname="org.apache.derby.jdbc.EmbeddedDataSource"
is-isolation-level-guaranteed="false">
<property name="databaseName" value="target/databases/derby"/>
<property name="createDatabase" value="create"/>
</jdbc-connection-pool>

<!--
<jdbc-resource pool-name="ArquillianEmbeddedH2Pool"
jndi-name="jdbc/arquillian"/>
<jdbc-connection-pool name="ArquillianEmbeddedH2Pool"
res-type="javax.sql.DataSource"
datasource-classname="org.h2.jdbcx.JdbcDataSource">
<property name="user" value="sa"/>
<property name="password" value=""/>
<property name="url" value="jdbc:h2:file:target/databases/h2/db"/>
</jdbc-connection-pool>
-->
</resources>


test-persistence.xml
=============

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="users" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>jdbc/chapter2</jta-data-source>
<properties>
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<property name="hibernate.dialect" value="org.hibernate.dialect.DerbyDialect" />
</properties>
</persistence-unit>
</persistence>


Finally, look at the change in addAsManifestResource

@Deployment
public static Archive<?> createDeployment() {
return ShrinkWrap.create(JavaArchive.class, "foo.jar").addClasses(OrderProcessor.class,
OrderProcessorBean.class, UserService.class, UserServiceBean.class,
ItemService.class,
ItemServiceBean.class, Bid.class, Bidder.class, Item.class).addAsManifestResource("test-persistence.xml", ArchivePaths.create("persistence.xml"));
}


That's all.


Joe

 
reply
    Bookmark Topic Watch Topic
  • New Topic