//FORM ACTIONS
public static final String ACTION_QUERY_FORM="queryForm";
public static final String ACTION_VIEW_FORM="viewForm";
public static final String ACTION_QUERY ="query";

//FORM FIELDS

public static final String FIELD_ACTION ="action";
public static final String FIELD_COMPANY ="company";
public static final String FIELD_FNAME="fname";
public static final String FIELD_LNAME="lname";
public static final String FIELD_CUSTOMER_ID="customer_id";
public static final String FIELD_EMAIL="email";
public static final String FIELD_PHONE="phone";
public static final String FIELD_ADDRESS1= "address1";
public static final String FIELD_ADDRESS2 ="address2";
public static final String FIELD_CITY="city";
public static final String FIELD_STATE ="state";
public static final String FIELD_ZIP ="zip";

//REQUEST ATTRIBUTES

public static final String ATTRIBUTE_CUSTOMER="customer";
public static final String ATTRIBUTE_CUSTOMER_LIST ="customer_list";

Now it is very simple to call both queries by EntityManager instance:
1. List<Customer> clist=em.createNamedQuery("findAllCustomers").getResultList();
2. Customer customer = (Customer) em.createNamedQuery("findCustomerById", Customer.class).setParameter("customerID", 2).getSingleResult();

Frankly I read that using named(static) queries is more efficient than dynamic queries which you use when call - em.createQuery(...);
Consider my way to declare primary key in entity:

This way key is incremented automatically when you insert new row and is not updatable or insertable by programmer. You must not insert primary key yourself if it is
annotated this way.

Next I know very little about jsp and servlets as I study Java Server Faces recommended by javaee6 tutorial, but I see that your persistence.xml is really poor and apparently it lacks <provider> element. Look at my persistence.xml:

Here 'demo00' is my name of database which is created automatically or when you ping your own connection-pool. I used Derby.
Of course this persistence provider should be set in classpath. I use maven and to include this provider in classpath I have in my pom.xml this:

Next I don't understand your url-patern in web.xml:

It seems to me wrong. As for me it simpler to write this -

It means that each page that ends with .jsp is processed by ControllerServlet. So welcome file will be like this:

True person is moral, false is right!

Nikhitha Pai
Greenhorn

Joined: Sep 17, 2012
Posts: 19

posted Sep 19, 2012 11:34:50

0

Thank you very much for your quick response. I have modified my persistence.xml as below:
<?xml version="1.0" encoding="UTF-8"?>
<persistence 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/persistence_1_0.xsd" version="1.0">

If i remove the line
<property name="eclipselink.ddl-generation" value="drop-and-create-tables" /> from the persistence .xml i am able to deploy the application without any messages . But when i try to open the url

First of all you should modify the following line in your persistence.xml:
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/nikdb;create=true"/>

This insures that your database is created when you deploy your application.

You should check if you created jdbc-resource described in persistence.xml --> <jta-data-source>jdbc/customer</jta-data-source>
If you didn't follow these steps:
1. create jdbc-connection-pool. For that type in command-line after you started glassfish server

At the end please make sure that you provided correctly path to welcome file in web.xml. About that I wrote in first reply.
Also your start or welcome page should be at the same level as WEB-INF folder in webapp folder,
otherwise your path to welcome page changes to <welcome-file><folder-name>/index.jsp</welcome-file>

Nikhitha Pai
Greenhorn

Joined: Sep 17, 2012
Posts: 19

posted Sep 19, 2012 21:38:25

0

Hello there,

I have followed your steps and created the jdbc-resource and jdbc-connection-pool.Everything is fine and it even creates a table .
The other changes i made are as follows :
POJO

I use NetBeans and for me correct project structure is.. Please tell me at first how you did that screenshot of your project in eclipse and then I shall give you screenshot of
my netbeans project

Thank you!

Nikhitha Pai
Greenhorn

Joined: Sep 17, 2012
Posts: 19

posted Sep 20, 2012 09:45:23

0

hello,
I have taken a printscreen (PrtScrn button on the keyboard) of the eclipse directory structure and pasted it in Ms Paint. In the forum i have included it as an attachment. I guess that answers how the screen shot was taken.
Coming back to the program, i am just curious to know if you have run it succesfully in Netbeans. Hope you would'nt mind.
I am really desperate to know what and where things have gone wrong in the deployed file. I copied this code and the directory structure from a well known book, so i am sure it must have been successfully tried out by the authors.

Also i went and checked at Mysql prompt the table is getting created when the deployment takes place

I think there is no error in the jdbc-resource and jdbc-connection-pool.Everything is fine . But i could not figure out why and how the controller servlet is not working as expected.

Thank you for your advise to take screenshot but button 'PrintScreenSysRq' on my old primitive keyboard doesn't work.

First of all in WEB-INF you are able to keep such files( at least what I have seen so far):
- faces-config.xml
- web.xml
- beans.xml to enable CDI
- glassfish-web.xml

I don't think it is a good idea to store something else in WEB-INF!. Your start page and all others pages should be
in the same folder that WEB-INF is! For instance you have:

It means that your index.jsp should be in :
WebContent/index.jsp
WebContent/WEB-INF/........
If you have this:

Your index.jsp should be in :
WebContent/rest/index.jsp
WebContent/WEB-INF/........

But instead of folder WebContent your IDE could generate folder with name 'webapp' or name 'web'.
When you create project in Eclipse you should take correct type of project.
It is good idea to take book's examples and try them at first. Use source code which is usually accompanying the book.
Please tell me does your book use Maven or not? Sorry for English.

Nikhitha Pai
Greenhorn

Joined: Sep 17, 2012
Posts: 19

posted Sep 20, 2012 23:22:41

0

Hello,

Thank you for all that explanation. I guess my application satisfies the requirements. My book is not using maven. Manually deploying at command prompt. IT uses eclipse, Weblogic 10 and MySql. I have no acccompanied cd's with the book.

Probably I didn't use book you use so I didn't try those examples. The best way for you is to have source code for that book. At the beginning of the book you must meet
information where to get source code! Usually source code is on author's site. I always download the book and its source code absolutely for free.

Great if your program runs correctly!

Nikhitha Pai
Greenhorn

Joined: Sep 17, 2012
Posts: 19

posted Sep 21, 2012 03:09:43

0

Hello there,
could you please post me 1 or 2 good examples with Entity beans as I need it urgently.Hope I am not bothering you too much.
Thnak you.

I have even better idea. As you use eclipse look on eclipse site for examples on JPA. They are simple and very important they contain a lot of tips to work
effeciently on Eclipse.

Nikhitha Pai
Greenhorn

Joined: Sep 17, 2012
Posts: 19

posted Sep 22, 2012 10:48:44

0

Hello there,
i would be glad to get more examples on the same topic. Please email to me to nikhithapai@gmail.com

Also the last 2 days i had been working on the example. Well i am glad to say that 2 errors have been rectified. Now i am able to view my index page.

Error no 1
My welcome file index.jsp was wrongly placed inside the WEB-INF folder. You had indeed pointed that out. Then i put all my jsp files in the same level as WEB-INF folder. So i am not getting the Resource not found error for that anymore.

Error no:2
When i deployed in weblogic i had wrongly put the META-INF FILE outside the WEB-INF folder when i tried in another computer. So this was giving the error No persistence unit named xxx available in the scope customer.war.
When i put the META-INF FOLDER AND as a result the persistence.xml file inside the WEB-INF that got rectified.
So iam happy i could reach the next stage.

Now the problem is once i hit the GO button from the index page it should invoke the Controller Servlet.Which at present is not happening. It is showing 404 error. Got to rectify that.

I am pasting below in the attachment the correct directory structure ,as how i follow it at present.

I have sent to you three emails with three examples. Write names of those archives which you received!

Nikhitha Pai
Greenhorn

Joined: Sep 17, 2012
Posts: 19

posted Sep 23, 2012 11:44:41

0

Hello,
I have got all the three archives you have sent.
Also i am happy that i could finally get the application deployed successfully and running.
The last mistake was i had placed the Web.xml inside classes folder of Web-INF.When I put it outside the classes directory, but inside the WEB-INF, things started working.
So the application is running smooth in glasssfish +eclipse+Mysql combination.
But not in Weblogic server.