Tuesday, May 30, 2006


TopLink JPA inside EJB 3.0 Container (JDeveloper 10.1.3)



Application designed satisfies same business requirements
as [1] and doesn't contain any hands written code line
for creating new orders and editing existing.
Deleting orders from Master-Detail page requieres modifying of
default method embedded into JSF managed Bean.


Import jpauser schema created in [2] in JDeveloper 10.1.3
environment. Tune Jdeveloper 10.1.3 environment to complete the task and generate Session EJB 3.0 for TopLink POJOs imported from jpauser schema.





Create all JSF pages (as *.jspx files backing up UI to Managed Beans),invoke method persistEntity(Object entity) for "Creation order" page (for particular item) , invoke method mergeEntity(Object entity) for "Editing order" page (for particular item)

Create table form has been used for data input.
Method persistEntity() refreshes target screen automatically.



Drag and drop persistEntity(Object) from Data Controls into
JSP area covering button "Submit".


Next step - edit action binding for the "persistEntity" button:




Same action should be performed for "order editing"
page regarding mergeEntity(Object entity) method and editing action binding for corresponding button.
Drag and drop "Delete" button of OrderTable from Data Controls:





Action invoked by "Delete" button (manual intervention):





Code details:


public String commandButton9_action() {

// Delete row from table

BindingContainer bindings1 = getBindings();
OperationBinding operationBinding1 =
bindings1.getOperationBinding("removeEntity");
Object result1 = operationBinding1.execute();
if (!operationBinding1.getErrors().isEmpty()) {
return null;
}

// Refresh detail table screen view

OperationBinding operationBinding =
bindings.getOperationBinding("Delete");
Object result = operationBinding.execute();
if (!operationBinding.getErrors().isEmpty()) {
return null;
}
return null;
}



As of June 21 2006 I found out that described method works only in
Jdeveloper 10.1.3 environment, project stops working properly even been deployed to standalone OC4J instance shipped with Jdeveloper
The reason of mistake is restarting of embedded OC4J instance with apps every time when apps restarts. Otherwise Master – Detail page won’t be properly refreshed after joint invocation removeEntity() & Delete.

View workaround for mentioned issue:-

Refreshing Master-Detail JSF page after inserting or deleting row from Detail table

Runtime screenshots:

Main page:


Orders for particular item:




Creating new order:




References.
1.http://www.oracle.com/technology/products/ias/toplink/jpa/tutorials/jsf-jpa-tutorial.html
2.http://bderzhavets.blogspot.com/2006/05/build-web-application-jsf-using-jpa.html

Friday, May 19, 2006


Build a Web Application (JSF) Using JPA (OTN's Tutorial)



Performing steps advised by :

JPA tutorial at OTN

I was experiencing the only one issue with command

$ ant -f build.xml generate-tables

and had to create schema through SQLPLUS


CREATE TABLE INVENTORY (COST NUMBER(19,4) NULL, PRICE NUMBER(19,4) NULL,
QUANTITY NUMBER(10) NULL, VERSION NUMBER(10) NULL,
ITEM_SKU NUMBER(19) NOT NULL, PRIMARY KEY (ITEM_SKU));

CREATE TABLE ORDER_TABLE (ORDERID NUMBER(19) NOT NULL,
CURRENTLOCATION VARCHAR2(255) NULL, QUANTITY NUMBER(10) NULL,
ARRIVALDATE DATE NULL, VERSION NUMBER(10) NULL,
ORDERINITIATED DATE NULL, ITEM_SKU NUMBER(19) NULL, PRIMARY KEY (ORDERID));

CREATE TABLE ITEM (SKU NUMBER(19) NOT NULL, NAME VARCHAR2(255) NULL,
CATEGORY VARCHAR2(255) NULL, VERSION NUMBER(10) NULL,
DESCRIPTION VARCHAR2(255) NULL, PRIMARY KEY (SKU));

ALTER TABLE INVENTORY ADD CONSTRAINT FK_INVENTORY_ITEM_SKU FOREIGN KEY (ITEM_SKU)
REFERENCES ITEM (SKU);

ALTER TABLE ORDER_TABLE ADD CONSTRAINT FK_ORDER_TABLE_ITEM_SKU FOREIGN KEY (ITEM_SKU)
REFERENCES ITEM (SKU);

CREATE TABLE SEQUENCE (SEQ_NAME VARCHAR2(50) NOT NULL,
SEQ_COUNT NUMBER(38) NULL, PRIMARY KEY (SEQ_NAME));

INSERT INTO SEQUENCE(SEQ_NAME, SEQ_COUNT) values ('SEQ_GEN', 0);
COMMIT;






As was advised by Gordon Yorke at OTN Toplink Forum (05/25/06)



glassfish-persistence-installer-v2-b01.jar was replaced by glassfish-persistence-installer-v2-b03.jar

The replacement resolves the issue.

It also runs fine with the same oracle database credentials simply recreating the schema.

Actually , sequence of builds:-



ant -f build.xml generate-tables
ant -f build.xml populate-data
ant -f build.xml package.webapp




may run recreating schema, repopulating data and regenerating war-file at any time.

The JSF application using JPA was successfully deployed to TomCat 5.5.16 on CentOS 4.2 box
hosting Oracle 10gR2 database.

Deployment Web Application using TomCat's Application Manager :-


Completed OK.



The manual mentioned above shows the basic steps of developing, packaging, and

deploying a Web application using the EJB 3.0 Java Persistence API (JPA).

In this application, a Java Server Faces (JSF) presentation layer will make

use of JPA for persistence outside of the EJB 3.0 container.

Runtime screenshots follows bellow:-