Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Close to get it. Just a little help

This is what I am meaning,
 
 
As a workaround you can call this on startup after login (postLogin SessionEvent): how to doit?
 
Thanks,
Jose

Sent: Saturday, April 17, 2010 2:29 PM
Subject: [eclipselink-users] Close to get it. Just a little help

Hi,
 
This is my code,
 
public class EmployeeProject extends org.eclipse.persistence.sessions.Project {
 
 //private static SessionManager sm;
 //private static Session session;
 //private DatabaseLogin login;
 
 public EmployeeProject() {
    setName("EmployeeProject");
    applyLogin();
   
    //addDescriptor(buildAddressDescriptor());
    //addDescriptor(buildEmployeeDescriptor());
    //addDescriptor(buildPhoneNumberDescriptor());
  }
 
  // Data source information
  public void applyLogin() {
    DatabaseLogin login = new DatabaseLogin();
 
    // use platform appropriate for underlying database
    login.usePlatform(
      new org.eclipse.persistence.platform.database.oracle.Oracle10Platform());
    login.setDriverClassName("oracle.jdbc.driver.OracleDriver");
    login.setConnectionString("jdbc:oracle:thin:@127.0.0.1:1521:XE");
    login.setUserName("employee");
    login.setPassword("employee");
 
    // Configuration Properties
 
      setDatasourceLogin(login);
      //Session s = this.createDatabaseSession();
         //s.setLogLevel(SessionLog.FINE);
         //((DatabaseSession)s).login();
 
         //this.login = login;
  }
  
  public Session getSession() {
   Session session = this.createDatabaseSession();
   session.setLogLevel(SessionLog.FINE);
   ((DatabaseSession)session).login();
   // store the session in the SessionManager instance
   SessionManager manager = SessionManager.getManager();
   manager.addSession("mysession", session);
   // retrieve the session
   session = SessionManager.getManager().getSession("mysession");
   return session;
  }
 
  /**
  * Descriptors are built by defining table info, setting properties
  * (caching, etc.) and by adding mappings to the descriptor
  */
 
  // SECTION: DESCRIPTOR
  public static ClassDescriptor buildEmployeeDescriptor() {
 
    RelationalDescriptor descriptor = new RelationalDescriptor();
 
    // specify the class to be made persistent
    descriptor.setJavaClass(model.Employee.class);
 
    // specify the tables to be used and primary key
 
    descriptor.addTableName("EMPLOYEE");
    descriptor.addPrimaryKeyFieldName("EMPLOYEE.EMP_ID");
 
    // Descriptor Properties
    descriptor.useSoftCacheWeakIdentityMap();  
    descriptor.setIdentityMapSize(100);
    descriptor.useRemoteSoftCacheWeakIdentityMap();
    descriptor.setRemoteIdentityMapSize(100);
    //descriptor.setSequenceNumberFieldName("EMPLOYEE.EMP_ID");
    //descriptor.setSequenceNumberName("ADD_SEQ");  
    descriptor.setAlias("Employee");
 
    // Mappings
    //DirectToFieldMapping cityMapping = new DirectToFieldMapping();
    //cityMapping.setAttributeName("city");
    //cityMapping.setFieldName("ADDRESS.CITY");
    //descriptor.addMapping(cityMapping);
 
    // Additional mappings are added to the descriptor using the addMapping method
 
    return descriptor;
  }
  
  public void getEmployees() {
         StoredProcedureCall spcall = new StoredProcedureCall();
         spcall.setProcedureName("EMPLOYEEPKG.GETALLEMPLOYEES");
         spcall.useNamedCursorOutputAsResultSet("MYCSR");
 
         List<DatabaseRecord> employees = (Vector) getSession().executeSelectingCall(spcall);
 
         for(DatabaseRecord dr: employees) {
             System.out.println("EMP_ID => " + dr.get("EMP_ID"));
             System.out.println("F_NAME => " + dr.get("F_NAME"));
             System.out.println("L_NAME => " + dr.get("L_NAME"));
             System.out.println(); System.out.println();
         }
     }
  
  public void getEmployee(BigDecimal employeeId) {
         StoredProcedureCall spcall = new StoredProcedureCall();
         spcall.setProcedureName("EMPLOYEEDETAILPKG.GETEMPLOYEEDETAIL");
         spcall.addNamedArgumentValue("EMPLOYEEID", employeeId);
         spcall.useNamedCursorOutputAsResultSet("MYCSR");
 
         ReadAllQuery query = new ReadAllQuery();
         query.setCall(spcall);
         //query.addArgument("EMPLOYEEID");
 
         ClassDescriptor descriptor = buildEmployeeDescriptor();
         //descriptor.getQueryManager().addQuery(query.getName(), query);
         query.setDescriptor(descriptor);
        
         /*
         Object returnValue = null;
         if (descriptor.isDescriptorForInterface()  || descriptor.hasTablePerClassPolicy()) {
             returnValue = descriptor.getInterfacePolicy().selectAllObjectsUsingMultipleTableSubclassRead(query);
 
           if (descriptor.hasTablePerClassPolicy() && returnValue == null) {
             // let it fall through to query the root.
           } else {
             query.setExecutionTime(System.currentTimeMillis());
           }
         }
         */
 
         //Vector args = new Vector();
         //args.add(employeeId);
 
         model.Employee employee = (model.Employee) getSession().executeQuery(query);
 
     }
  
  
  public static void main(String[] args) {
         // TODO code application logic here
   EmployeeProject ep = new EmployeeProject();
         BigDecimal employeeid = new BigDecimal(32);
         try {
          ep.getEmployee(employeeid);
         } catch (java.lang.Exception ex) {
          ex.printStackTrace();
         }
     }
}
But when I run the app I get the following exception,
 
[EL Info]: 2010-04-17 14:09:55.859--DatabaseSessionImpl(9519074)--Thread(Thread[main,5,main])--EclipseLink, version: Eclipse Persistence Services - 2.0.1.v20100213-r6600
[EL Config]: 2010-04-17 14:09:55.906--DatabaseSessionImpl(9519074)--Connection(19551481)--Thread(Thread[main,5,main])--connecting(DatabaseLogin(
 platform=>Oracle10Platform
 user name=> "employee"
 datasource URL="" "jdbc:oracle:thin:@127.0.0.1:1521:XE"
))
[EL Config]: 2010-04-17 14:09:56.343--DatabaseSessionImpl(9519074)--Connection(19058102)--Thread(Thread[main,5,main])--Connected: jdbc:oracle:thin:@127.0.0.1:1521:XE
 User: EMPLOYEE
 Database: Oracle  Version: Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
 Driver: Oracle JDBC driver  Version: 10.2.0.1.0XE
[EL Info]: 2010-04-17 14:09:56.375--DatabaseSessionImpl(9519074)--Thread(Thread[main,5,main])-- login successful
[EL Fine]: 2010-04-17 14:09:56.89--DatabaseSessionImpl(9519074)--Connection(19058102)--Thread(Thread[main,5,main])--BEGIN EMPLOYEEDETAILPKG.GETEMPLOYEEDETAIL(EMPLOYEEID=>?, MYCSR=>?); END;
 bind => [32, => MYCSR]
[EL Warning]: 2010-04-17 14:09:57.218--DatabaseSessionImpl(9519074)--Thread(Thread[main,5,main])--java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
 at java.util.ArrayList.RangeCheck(ArrayList.java:547)
 at java.util.ArrayList.get(ArrayList.java:322)
 at org.eclipse.persistence.internal.descriptors.ObjectBuilder.getPrimaryKeyClassifications(ObjectBuilder.java:2225)
 at org.eclipse.persistence.internal.descriptors.ObjectBuilder.extractPrimaryKeyFromRow(ObjectBuilder.java:1870)
 at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildObject(ObjectBuilder.java:455)
 at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildObjectsInto(ObjectBuilder.java:846)
 at org.eclipse.persistence.queries.ReadAllQuery.executeObjectLevelReadQuery(ReadAllQuery.java:467)
 at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeDatabaseQuery(ObjectLevelReadQuery.java:997)
 at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:675)
 at org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:958)
 at org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:432)
 at org.eclipse.persistence.internal.sessions.AbstractSession.internalExecuteQuery(AbstractSession.java:2322)
 at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1225)
 at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1207)
 at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1167)
 at main.model.EmployeeProject.getEmployee(EmployeeProject.java:157)
 at main.model.EmployeeProject.main(EmployeeProject.java:167)
I have been googling but I have not found any solution to this issue.
I know this happen since what I have read frecuently.
 
PLease help.
 
Regards,
Jose
 


_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

Back to the top