Hot questions for Using Enterprise JavaBeans in oracle

Question:

I am working with OBIEE 12c. I am trying to call a java method to save the report into the local file system with an agent. I followed the steps for 11g version at this link http://docslide.us/documents/how-to-create-and-invoke-enterpise-java-beans-ejb-using-the-action-framework.html .I used exactly the same application names, project names, and configurations.After everything I go to OBI and click on the invoke a java method link. This is what I am getting. There is no method named "ArchiveReport". Does anyone know what might be wrong?


Answer:

I finally figured out there was an issue with my mappedName for the EJB class.

I found a working example compared everything, found out the mappedName for the EJB class has to be ejb/xxxx. After changing this and regenerated the ear file. I am able to see my EJB now.

Question:

I am trying to downgrade from Jdeveloper 12.2.1.2.0 to Jdeveloper 12.1.3.0.0 but i faced incompatibility with java libraries.

I already followed these instructions http://markchensblog.blogspot.com/2014/06/change-jdk-used-by-jdeveloper.html and i replaced the jdk of Jdeveloper 12.1.3.0.0 with the one in Jdeveloper 12.2.1.2.0 but i still can't run my project and em.createStoredProcedureQuery is not working nor @Temporal(TemporalType.DATE)

should i update something else ?


Answer:

From the 12.1.3 certification doc:

JDeveloper 12.1.3 can be configured to develop/compile against JDK 8, and introduces support for JDK 8 language features. However, the JDeveloper process must be running with JDK 7.

So you can compile it for 1.8.0 ut it would not run the app e.g. if you use ADF. You need to make it work with JDK 1.7.0

Question:

I have a Singleton EJB that initializes two entities in the beginning:

@Startup
@Singleton
@Lock(LockType.READ)
public class PetShopSingleton {

@Inject
private AnimalRepository animalRepository;

private Animal cat;

private Animal dog;

@PostConstruct
public void init() {

    cat = AnimalRepository.findByType(AnimalType.CAT);

    dog = AnimalRepository.findByType(AnimalType.DOG);
}
}

The entities are initialized from a service running a named query:

@Stateless
public class AnimalRepository extends BaseRepository {

public Animal findByType(AnimalType type) {
    Map<String, Object> params = new HashMap<>();
    params.put("type", type);

    return findOneByNamedQuery("Animal.findByType", params,
            Animal.class);
}
}

The findOneByNamedQuery is a method in the abstract BaseRepository class:

public <T> T findOneByNamedQuery(String queryName, Map<String, Object> parameters, Class<T> clazz) {
        TypedQuery<T> typedQuery = entityManager.createNamedQuery(queryName, clazz);

    applyParameters(parameters, typedQuery);

    List<T> results = typedQuery.getResultList();
    if (!results.isEmpty()) {
        return results.get(0);
    }

    return null;
}

The enumerable class used in the named query looks like this:

public enum AnimalType {
    CAT,
    DOG;
}

And finally the persistent entity:

@Entity
@Table(name = "ANIMALS")
@NamedQueries({
    @NamedQuery(
        name = "Animal.findByType",
        query = "select a from Animal a where a.type = :type"
    )
})
public class Animal {

    @Enumerated(EnumType.STRING)
    private AnimalType type;

    public AnimalType getType() {
        return type;
    }

    public void setTyp(AnimalType type) {
        this.type = type;
    }

}

The one entity (cat) was an older one and was registered in the database, the newer one (dog) has been registered recently. The issue here is that the service called in the init() function to find the two entities with the named query finds only the cat. The dog is returned null although there is an entry in the database with a TYPE column equal with DOG.

Can anyone help me or give me possible reasons why this is happening?

The database is an Oracle DB.


Answer:

OK I solved the issue, there was a column in the table with a file path for the animal avatar that started with C:/path/to/avatar, I changed it to /path/to/avatar and it worked. Still don't know why this happens but it's fine now :)

Question:

I have a performance issue, but, despite what it suggests in the subject, it may not be that I am using createNativeQuery. I have one fairly large query that I pass as a string to createNativeQuery. The query contains several JOINs, and is associated with 5 entities. The query takes, on average, 20 - 25 seconds to run. I have experimented, like trying the createQuery method and using the setFlushMode(FlushModeType.COMMIT), setMaxResults() and setFirstResult() methods, but made no difference.

We are using JBoss EAP 6.2 in a JTA container-managed environment, using EJB 3.0, JPA 2.1, Hibernate 4.2. The IDE I use is NetBeans 8.0.2

Yet, if I run the query directly in a SQL tool like DB Visualizer it takes milliseconds. I suspect it might have something to do with Hibernate, but am not sure. None of the Entity classes contains a collection, although there are specific relationships between the tables, as indicated in the JOIN statements in the query. I have attached some code (including the query) below.

I am hoping to retain the query as-is, but if a suggestion is made that would make it more efficient I am open to that. I appreciate that it might be difficult to answer since the query below may be difficult to analyze without knowing the database schema (this is a company project, so can only provide pseudo code in some instances). I have also not provided the Entity or Facade classes, but can provide those later if necessary. Any help would be greatly appreciated. Thank you!

public List<String> searchSingleView (String sourceSystem, String sourceClientId, String convertedClientId, String policyNum) {

   String sqlQuery = "SELECT DISTINCT " +
      "MDMCUST_ORS.C_BO_PARTY_XREF.ROWID_XREF, " +                                      "MDMCUST_ORS.C_BO_CONTRACT.LAST_ROWID_SYSTEM, " +
                                    "MDMCUST_ORS.C_BO_CONTRACT.SRC_POLICY_ID, " +
                                    "MDMCUST_ORS.C_BO_CONTRACT.ISSUE_DT, " +
                                    "MDMCUST_ORS.C_BO_PARTY_XREF.SRC_CLIENT_ID, " +
                                    "MDMCUST_ORS.C_BO_PARTY_XREF.PERS_FULL_NAME_TXT, " +
                                    "MDMCUST_ORS.C_BO_PARTY_XREF.PERS_SRC_NAME_TXT, " +
                                    "MDMCUST_ORS.C_BO_PARTY_XREF.ORG_LEGAL_NAME_TXT, " +
                                    "MDMCUST_ORS.C_BO_PARTY_XREF.ORG_SRC_NAME_TXT, " +
                                    "MDMCUST_ORS.C_BO_PARTY_XREF.ORG_LEGAL_SFX_TXT, " +
                                    "MDMCUST_ORS.C_BO_PARTY_XREF.ORG_NAME_TXT, " +
                                    "MDMCUST_ORS.C_BO_PARTY_XREF.SIN_BIN_TEXT, " +
                                    "MDMCUST_ORS.C_BO_PARTY_XREF.PERS_BIRTH_DT, " +
                                    "MDMCUST_ORS.C_BO_PARTY_POSTAL_ADDR_XREF.LAST_UPDATE_DATE, " +
                                    "MDMCUST_ORS.C_BO_PARTY_POSTAL_ADDR_XREF.COMPLETE_ADDRESS_TXT, " +
                                    "MDMCUST_ORS.C_BO_PARTY_POSTAL_ADDR_XREF.TOPLINE_POSTAL_ADDR_TXT, " +
                                    "MDMCUST_ORS.C_BO_PARTY_POSTAL_ADDR_XREF.CITY_NAME, " +
                                    "MDMCUST_ORS.C_BO_PARTY_POSTAL_ADDR_XREF.COUNTRY_NAME, " +
                                    "MDMCUST_ORS.C_BO_PARTY_POSTAL_ADDR_XREF.POSTAL_CD, " +
                                    "MDMCUST_ORS.C_BO_PARTY_POSTAL_ADDR_XREF.POSTAL_ADDR_PURPOSE_CD, " +
                                    "MDMCUST_ORS.C_BO_PARTY_POSTAL_ADDR_XREF.STATE_PROVINCE_NAME, " +
                                    "MDMCUST_ORS.C_BO_PARTY_POSTAL_ADDR_XREF.BAD_ADDR_IND " +
                                    "FROM MDMCUST_ORS.C_BO_PARTY_XREF " +
                                    "LEFT JOIN MDMCUST_ORS.C_BO_PARTY_POSTAL_ADDR_XREF ON " + 
                                    "(MDMCUST_ORS.C_BO_PARTY_POSTAL_ADDR_XREF.S_PARTY_ROWID = MDMCUST_ORS.C_BO_PARTY_XREF.SRC_CLIENT_ID " +
                                        "OR MDMCUST_ORS.C_BO_PARTY_POSTAL_ADDR_XREF.S_PARTY_ROWID = MDMCUST_ORS.C_BO_PARTY_XREF.CONVERTED_CLIENT_ID) " +      
                                    "LEFT JOIN MDMCUST_ORS.C_LU_CODES ON MDMCUST_ORS.C_BO_PARTY_POSTAL_ADDR_XREF.POSTAL_ADDR_PURPOSE_CD = MDMCUST_ORS.C_LU_CODES.CODE " +
                                    "LEFT JOIN MDMCUST_ORS.C_BO_PARTY_REL ON MDMCUST_ORS.C_BO_PARTY_XREF.ROWID_OBJECT = MDMCUST_ORS.C_BO_PARTY_REL.FROM_PARTY_ROWID " +
                                    "LEFT JOIN MDMCUST_ORS.C_BO_CONTRACT ON MDMCUST_ORS.C_BO_PARTY_REL.CONTRACT_ROWID = MDMCUST_ORS.C_BO_CONTRACT.ROWID_OBJECT " +
                                "WHERE MDMCUST_ORS.C_BO_CONTRACT.LAST_ROWID_SYSTEM IN ('E-CAPSIL', 'C-CAPSIL', 'INGENIUM') " +
                                    "AND (UPPER(MDMCUST_ORS.C_BO_PARTY_XREF.SRC_CLIENT_ID) = ? " +
                                    "     OR UPPER(MDMCUST_ORS.C_BO_PARTY_XREF.CONVERTED_CLIENT_ID) = ? " +
                                    "     ) " +
                                    "AND UPPER(MDMCUST_ORS.C_BO_CONTRACT.SRC_POLICY_ID) = ? " +
                                    "AND MDMCUST_ORS.C_BO_PARTY_POSTAL_ADDR_XREF.POSTAL_ADDR_PURPOSE_CD = '56|07'" +
                                    "AND MDMCUST_ORS.C_BO_PARTY_XREF.HUB_STATE_IND = '1' " +
                                    "AND MDMCUST_ORS.C_BO_CONTRACT.HUB_STATE_IND = '1' " +
                                    "AND MDMCUST_ORS.C_BO_PARTY_POSTAL_ADDR_XREF.HUB_STATE_IND = '1' " + 
                                    "AND MDMCUST_ORS.C_LU_CODES.HUB_STATE_IND = '1'" +
                                    "AND ROWNUM = 1";

try {
            querySingleView = emSingleView.createNativeQuery(sqlSingleViewQuery)
                                          .setParameter(1, sourceClientId)
                                          .setParameter(2, convertedClientId)
                                          .setParameter(3, policyNum);
            querySingleViewResult = (List<String>) querySingleView.getResultList();
        } catch (NoResultException nre) {
          // Issue a validation failure message to prevent query from continuing.
            FacesContext.getCurrentInstance().validationFailed();
            // Display error message to user
            JsfUtil.addErrorMessage(ResourceBundle.getBundle("/Bundle").getString("fatcaSearchSingleViewFailMessage"));
            // Generate log entry on server
            java.util.logging.Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, nre);
        }
        return querySingleViewResult;
    }

Answer:

This

UPPER(MDMCUST_ORS.C_BO_CONTRACT.SRC_POLICY_ID) = ? " 

will most likely prevent Oracle from using an index on SRC_POLICY_ID. MIf it is an ID I would expect it to be a number so an UPPER should not be necessary. If you really do need the UPPER than you propably should create a function based index on the column.

But without access to the database performance issues are hard to solve.

P.S.: And do you really need the DISTINCT and ROWNUMBER=1. I think you should write the query that you get only one row by using the proper conditions in the WHERE clause.

Question:

I am total newbie in Java and EE especially. I started an EE project that should provide REST API which will handle 2 entities in remote Oracle Database. I am using NetBeans because it is the only way how to accomplish anything in Enterprise Java (as I see it now).

What I've done:

  1. I created JDBC pool in Glassfish (v4.1-13). I can ping the pool successfully. Then I created JDBC Resource for the pool.
  2. I generated Entity classes for the two entities I need to handle.

<persistence version="2.1" xmlns...>
  <persistence-unit name="semestralka-ejbPU" transaction-type="JTA">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>jdbc/dbs</jta-data-source>
    <class>cz.ctu.bitjv.kopecj24.semestralka.entities.Food</class>
    <class>cz.ctu.bitjv.kopecj24.semestralka.entities.User</class>
    <exclude-unlisted-classes>true</exclude-unlisted-classes>
    <properties>
      <property name="eclipselink.target-database" value="Oracle"/>
    </properties>
  </persistence-unit>
</persistence>

Answer:

Double check the connection pool name in persistence unit and glassfish server. Also could you update your question with the entities.

Question:

I have a callableStatment, upon execution I get the below error

    try{
callableStatement.executeQuery()
}
    catch (Throwable t) {
                throw new Exception(t);

            } 
            finally {
                closeResultSet(rs);
                closeCallableStatement(callableStatement);
                closeConnection(dbConnection);

            }
javax.ejb.EJBTransactionRolledbackException: ORA-30926: unable to get a stable set of rows in the source tables

After some time I get Database Error of "Too man open cursors"

I know that the procedure is throwing the error due to duplication, I want to know why the Cursors aren't closed as it seems finally block is not doing what I need and what is the proper way to close them


Answer:

I think you are executing a merge query and there is more than 1 row id returned. And this is the reason for that exception. Also when the first duplicate row is returned, there itself the exception is thrown. And before the query is even executed you are trying to close it. That should be the reason for the cursor not closing properly. Try adding a distinct keyword in your query to avoid duplicates. Eg: MERGE INTO table_1 a USING (SELECT distinct ta.ROWID row_id FROM table_1 a ,table_2 b ,table_3 c WHERE ) src ON ( a.ROWID = src.row_id ) WHEN MATCHED THEN ;As there is a rollback involved, it comes under System Exception. And Application Exceptions are not rolled back.