Saturday, January 21, 2017

TopLink - Common Errors - ClassCastException

Are you facing a class cast exception while using Oracle TopLink?
For example - com.entity.Organization cannot be cast to com.entity.Organization

In my experience, this issue occurred sporadically and was not consistent. The reason this occurs is because multiple instances of Entity Manager have been created in your application session. The class loader is hence unable to determine the instance of the class that is to be loaded

Here is how I was able to workaround the issue:

  • Create a listener class (myListner) as shown below
    • Override the contextInitialized method to create an entity manager as soon as the application session is initiated
    • Override the contextDestroyed method to release the entity manager as soon as the application session ends
  • This will ensure only a single instance of entity manager exists at any point in time. Thus, eliminating the root cause.


package com.db.dao;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class myListener implements ServletContextListener {
    private static String persistenceUnitName = "Persistent_Unit_Name";
    private static EntityManagerFactory emf = Persistence.createEntityManagerFactory(persistenceUnitName);

    public myListener() {
    }

    @Override
    public void contextInitialized(ServletContextEvent event) {
        if (!emf.isOpen()) {
            emf = Persistence.createEntityManagerFactory(persistenceUnitName);
        }
    }

    @Override
    public void contextDestroyed(ServletContextEvent event) {
        if (emf != null) {
            emf.close();
        }
    }

}

  • Register the listener class in your web.xml
<web-app version="2.5" 
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
   xmlns="http://java.sun.com/xml/ns/javaee" 
   xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
   version="2.5" xmlns="http://java.sun.com/xml/ns/javaee">
  <display-name>myTopLinkProject</display-name>
  <description>Sample TopLink Application</description>
  <filter>
    <filter-name>JpsFilter</filter-name>
    <filter-class>oracle.security.jps.ee.http.JpsFilter</filter-class>
    <init-param>
      <param-name>enable.anonymous</param-name>
      <param-value>true</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>JpsFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
  </filter-mapping>
  <listener>
    <description>Web Application Listener</description>
    <display-name>myListener</display-name>
    <listener-class>ul.iam.db.dao.myListener</listener-class>
  </listener>
</web-app>





Hope you find this helpful! Please share your feedback below.

CaptiveCode


How To: Configure JTA Data Source in TopLink persistence.xml

Here is an example of a persistence.xml when using a data source:

<persistence version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
   xmlns="http://java.sun.com/xml/ns/persistence" 
   xsi:schemalocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
  <persistence-unit name="Sample" transaction-type="JTA">
    <description>Attribute Data Store</description>
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>jdbc/SampleDataSource</jta-data-source>
    <properties>
      <property name="toplink.logging.level" value="INFO">
    </property></properties>
  </persistence-unit>
</persistence>





Please share your feedback below. Hope you find this helpful!

CaptiveCode


Saturday, September 17, 2016

How To: Launch Oracle Form (FMB/ D2K) from OAF Page

Given below is the code snippet to invoke Oracle Forms from OAF page. However, it can get tricky when you need to pass parameters. Read the use cases further below for illustrations.

Launch Oracle Form from OAF

1. Add a button or link on the OAF page using form personalization. Note if the ID of the button/link.
2. Extend the controller of the page and override the processFormRequest method as follows:
public void processFormRequest(OAPageContext pageContext, OAWebBean webBean) { 
 super.processFormRequest(pageContext, webBean);

 if (pageContext.getParameter("Go") != null) { 
  // form:APPLICATION_SHORT_NAME:RESPONSIBILITY_KEY:DATA_GROUP_NAME:FORM_FUNCTION_NAME
  String destination =  "form:FND:APPLICATION_DEVELOPER:STANDARD:FND_FNDPOMPO"; 

  //Invoke the Form
  pageContext.forwardImmediatelyToForm(destination);               
 } 
}


Use Case#1: Launch Oracle PO Form from OAF to Create PO

Edit the destination string as follows to launch the PO Form:

String destination = "form:PO:PURCHASING_OPERATIONS_AIG:STANDARD:PO_POXPOEPO";


Use Case#2: Launch Oracle PO Form (with Parameters) from OAF to Edit PO

The parameters for a given form vary. The below-listed parameters are specific to a PO form. For other FMB forms, I would recommend to download the FMB and review it Oracle Forms Builder so that you can identify the parameters you need to pass.
 
  /**
    * Parameters: 
    * PO_HEADER_ID 
    * = poHeaderId => This is the document ID
    * 
    * ACCESS_LEVEL_CODE 
    *  = MODIFY => This indicates to open the form in edit mode
    *
    * POXPOEPO_CALLING_FORM 
    * = OAF => This is calling function name. 
    *    If your OAF page is registered as a function, 
    *    provide the function short name here
    *
    * G_QUERY_FIND 
    * = FALSE
    *
    */
 
    String destination = "form:PO:PURCHASING_OPERATIONS_AIG:STANDARD:PO_POXPOEPO:" 
       + "PO_HEADER_ID=\"" + poHeaderID 
       + "\" " + "ACCESS_LEVEL_CODE=\"MODIFY\" " 
       + "POXPOEPO_CALLING_FORM=\"OAF\" " 
       + "G_QUERY_FIND=\"FALSE\"";
 
    pageContext.forwardImmediatelyToForm(destination);



Please share your feedback below. Hope you find this helpful!

CaptiveCode


Saturday, September 10, 2016

GIT: How to create empty branch in GIT?

Execute the following command on the GIT terminal:

#Create Empty Branch
git checkout --orphan branch_name

#Clear Working Directory
git rm --cached -r .

Please share your feedback below. Hope you find this helpful!

CaptiveCode


Tuesday, August 30, 2016

How To: Perform "Date Conversion" in ADF/ OAF/ JAVA

I run into the struggle of converting one data type to another all the time. And obviously, I don't recollect instantly how to convert one from another. So here's some notes for me & hopefully they will useful for you as well.

// 1. Get Date from Calendar 
 int year=2016; int month=1; int date=1;
 Calendar cal = Calendar.getInstance();
 cal.set(year, month, date);
 java.util.Date utilDate = cal.getTime();

// 2. Convert java.util.Date to java.sql.Date
 java.util.Date utilDate = new java.util.Date();
 java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());

// 3. Convert java.sql.Date to oracle.jbo.domain.Date
 java.sql.Date sqlDate = new java.sql.Date();
 new jbo.domain.Date(sqlDate);
 /* To get current date & time in jbo.domain.Date */
 java.util.Date utilDate = new java.util.Date();
 java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());
 oracle.jbo.domain.Date jboDate = new oracle.jbo.domain.Date(sqlDate);

// 4. Convert java.util.Date to java.sql.Timestamp
 java.util.Date utilDate = new java.util.Date();
 java.sql.Timestamp timestamp_now = new java.sql.Timestamp(utilDate.getTime())

Please share your feedback below. Hope you find this helpful!

CaptiveCode

Thursday, August 25, 2016

OAF: CSS Classes for OA Components

Here is the link where all the OAF CSS classes for OA Components are published:
http://download.oracle.com/tech/blaf/specs/textstandards.html#general

 Do not go by the look and feel of this page. The CSS classes will reflect the look and feel of your EBS environment.

Please share your feedback below. Hope you find this helpful!

CaptiveCode

How To: Redirect to a new page in OAF

The method pageContext.setForwardURL() is to redirect to a new page. There are several ways in which the method can be used in your controller class:

Option 1:

 //Create HashMap to include destination page parameters
 HashMap hm = new HashMap();
 hm.put("poNumber",poNumber);
 hm.put("pMode","createMemo");

 //Forward to destination page
 pageContext.setForwardURL(
  "OA.jsp?page=/xxcc/oracle/apps/ar/demo/webui/myDemoPG", // Path to the destination page
  null,  // No need to specify with KEEP_MENU_CONTEXT
  OAWebBeanConstants.KEEP_MENU_CONTEXT, // No change in the menu context. Keep same as source page 
  null,  // No need to specify with KEEP_MENU_CONTEXT
  hm,  // HashMap with page parameter
  true,  //Retain AM state.
  OAWebBeanConstants.ADD_BREAD_CRUMB_YES, //Show breadcrumbs
  OAWebBeanConstants.IGNORE_MESSAGES //Ignore any messages
 ); 

Please share your feedback below. Hope you find this helpful!

CaptiveCode