Object Casting

hi ,i have a question for .Base on this example below , i need to understand some casting basic .I understand how premitives values widening rules works but not on object casting rules.
Question 1.
Okay ,base on the example below why 'c=(Test) a' will always give compile error while "a=b" does not .Let takes this example , b already extends A and should have information of A class while A only have it own .I know i was thinking another way round.Can any one help.
Question 2.
How to make " c = (Test) a to run without any problem ,as long as a is assign to a is ok.
Question 3.
I have a statement from Khalid book page 202 and i don't understand .
First statement:=Conversion which preserve the inheritance is a relationship are allowed ,other conversion      require an explicit case or are illegal.
Fecond statement:=There is no notion of promotion for reference values.
Question 4.
What is the benefit of using casting and when we need to use it .Can give a short example.??
class A {int Athing = 1;}
class B extends A {int Bthing = 2;}
class Test extends A
{ int Cthing = 3;
public static void main(String args[])
A a = new A();
B b = new B();
Test c = new Test();
//c = (Test) a; //runtime error
a = b;

Ron, does your mommy know you're here? Shoudn't you be out riding your bike or doing homework or watching X Men or something instead of interrupting the grown-ups?
Wikey: The answer to your question is that you can always (and implicitly) cast to a subclass because the subclass is always a member of the class, but you can't always even explicitly cast to the parent or higher class. To give a concrete example, all Toyota Camries are cars, but not all cars are Toyota Camries. There are things you can do with a Toyota Camry that you can't do with all cars. In your code, if you had coded A a = new Test();, you woudn't have a runtime error.
Doug

Similar Messages

  • Hi i just to want to know when we use object casting..

    sorry about this newbie question i ve already asked to my tutor but
    didn't get it...
    i just wonder what will happen if we cast object..
    i just can't imagin..coz im just bit slow on creative thinking...
    my currently writing code is like this..
    Integer nextCustID = new Integer("123456");
    Customer customer = new Customer(nextCustID, "Fred");
    customers.put("First", customer);
    customer = (Customer) customers.get("First");
    System.out.println(customer);i don't know about object casting...............................

    You don't cast objects. You just cast references - widening or narrowing their "scope" along the inheritance hierarchy.
    String s = new String("Hello");
    Object o = (Object) s; // Explicit cast not necessary, just for clarification
    String s = (String) o;While "hello" might appear as a String, then as an Object, then again as a String, it is always a String. Only the reference type to it changes.

  • Object casting: confusion in ABAP Objects: Complete Reference book

    Hi,
    During Object Assignments using casting, is a Type Test carried out during the syntax check or at runtime?
    A.5.2.2 (page 1008) of 'ABAP Objects: The Complete Reference' says about Widening Cast: "...you must check at runtime...". However on the next page under A.5.3.2 it says of Widening Cast in Data References: "The syntax check precludes...".
    A.5.4 (page 1010) concerns Assignments between Object Reference Variables, but makes no mention of whether checks are carried out by a syntax check or at runtime.
    Also nowhere does it mention when Type Tests for Narrow casting takes place. Can anyone clear my confusion please? Unfortunatly I don't know enough about this stuff to test by writing some code.
    Thanks.

    William,
    Your questions can be answered by the following rule for object references, which I found in the book "ABAP Objects" by Horst Keller and Sascha Krüger:
    "... that the static type of the target variable must be equal to or more general than the dynamic type of the source variable."
    Here "static type" means the type with which an object reference variable is declared. "Dynamic type" is the type that the object reference variable has at runtime. The dynamic type of an object reference is always more special than its static type, otherwise a runtime error occurs.
    With this rule all your questions can be answered:
    1. The Narrowing Cast is always checked during the syntax check. Example:
    DATA o_ref1 TYPE REF TO object.
    DATA o_ref2 TYPE REF TO class_1.
    o_ref1 = o_ref2.  
    Here the reference o_ref2 has a dynamic type "class_1" or a subclass of it, which is narrower than its static type "class_1", which is narrower than the static type "object" of the reference o_ref1. Therefore, the syntax check says that the assignment is OK.
    2. The Widening Cast is always checked at runtime and requires an assignment using the operator ?=. If you use the operator = in the assignment, a syntax error occurs. Therefore the following  example produces a syntax error (try it yourself):
    DATA o_ref1 TYPE REF TO object.
    DATA o_ref2 TYPE REF TO class_1.
    o_ref2 = o_ref1.  
    The correction for this syntax error is:
    DATA o_ref1 TYPE REF TO object.
    DATA o_ref2 TYPE REF TO class_1.
    o_ref2 ?= o_ref1.
    Now the syntax check is satified, and the correctness of the widening cast is checked at runtime.
    Kind regards,
    Michael Kraemer
    Message was edited by: Michael Kraemer

  • Object Casting in a JSP

    When getting data from the usual HttpSession object, I understand how the following (for simplicity) hypothetical line of code works:
    AccountInfo someAccount = (AccountInfo) session.getAttribute( ... );
    Here, assume that "AccountInfo" is a bean i.e., implements serializable and has standad getters and setters. So far nothing special but wait... What about the following variation:
    AccountInfo someAccount = (AccountInfo) (List) session.getAttribute( ... );
    The surprising thing was that the someAccount object has its data populated with items from the list! Why do I say such silly things? Well the code that follows leads me to that conclusion:
    AccountInfo someAccount = (AccountInfo) (List) session.getAttribute( ... );
    this.doSomething(accInfo);
    It's not obvious to me when the getters and setters of accInfo were called?? Can someone provide an explanation? I was not aware of this mechanism. Should I get a new Java book?
    Thanks!

    EDITED VERSION OF THE ABOVE POST
    When getting data from the usual HttpSession object, I understand how the following hypothetical line of code works:
    AccountInfo someAccount = (AccountInfo) session.getAttribute( ... );
    Here, assume that "AccountInfo" is a bean i.e., implements serializable and has standad getters and setters. So far nothing special but wait... What about the following variation (I saw something like this in some code at work)
    AccountInfo someAccount = (AccountInfo) (List) session.getAttribute( ... );
    So its just two sequential casts, right? What surprised me, was that the someAccount bean has its data populated with items from the list! Can someone provide an explanation? I was not aware of this mechanism. Should I get a new Java book?
    Thanks

  • Int to Object casting

    This should be a simple question, I just cant seem to get it.
    I want to cast an int to an Object.
    // --- Does not work
    int num = 16;
    Object obj = num;
    // --- Does not work
    int num = 16;
    Object obj = (Object)num;
    // --- Does not work
    Object obj = (Object)16;
    Anyone know?

    You can't cast a primitive. You can do this for your problem:
    Integer intObject = new Integet(intPrimitive);Lee

  • When should object casting be used?

    Hi,
    just wondering something. Saw there that returning objects from methods and downcasting the returned object is bad. When should casting be used? I currently have a program that has an object that contains a HashMap as a field. When I try retrieve objects from the HashMap using the relevant key, I have to cast them to what they were originally! Is this bad programming practice or is it the only way to do things?
    Thanks.
    // example of retrieving object from key
    dbDirectory = (String)dbInfo.get("dbDirectory");

    LeWalrus wrote:
    Hi,
    just wondering something. Saw there that returning objects from methods and downcasting the returned object is bad. When should casting be used? I currently have a program that has an object that contains a HashMap as a field. When I try retrieve objects from the HashMap using the relevant key, I have to cast them to what they were originally! Is this bad programming practice or is it the only way to do things?
    Thanks.
    // example of retrieving object from key
    dbDirectory = (String)dbInfo.get("dbDirectory");
    Before generics, this was a perfectly acceptable practice. Generally speaking, you use type-casting when the compiler is unable to ensure the type validity at compile-time, but you know it is correct, so you supply the extra information to the compiler so it knows everything is correct. Sometimes you need to circumvent the strong type-checking part of the language for flexibility, but this is something that should be used very sparingly.
    Now it would be better to use generics so that the compiler will know at compile time that the values in your map are Strings, instead of just Objects.

  • Object cast - J2EE to ActionScript strange problem

    Hello,
    I am working in a project with multiple layers composed by Flash+Flex; BlazeDS; J2EE+Hibernate.
    I have some services to get all the data from database and I have a strange problem when I try to cast some objects from J2EE to ActionScript via BlazeDS Services. This is the structure that I have in my project:
    Oracle
    Table ServicePetitions (a table with all the data about a service petition)
    J2EE+Hibernate
    ServicePetition object (mapping object generated by hibernate)
    ServicePetitionId object (multiple key object generated by hibernate)
    ServiceServicePetitions object (the service to use in blazeDS)
    Flex 4 (All the objects generated by Flex Builder at the time of map the service)
    _Super_ServiceServicePetitions
    ServiceServicePetitions
    _Super_ServicePetitions
    _Super_ServicePetitionId
    _Super_ServicePetitionEntityMetadata
    _Super_ServicePetitionIdEntityMetadata
    ServicePetition
    ServicePetitionId
    Normally I call the service and later I try to get the data using a CallResponder object to make the assignation lastresult = ServicePetition; except when I use a datagrid that automaticly use the CallResponser.lastresult as dataprovider, without any assignation (important, always work!)
    The fact is that when I try to make the assignation all works alright, I get all the data, I can work with those data, all goes perfect, but...when I make the second call, the assignation (callresponder.lastresult = ServicePetition) does not assign anything.
    This is the code of the assignation:
        private var respPs:CallResponder;
        private var servPs:ServiceServicePetitions;
        private var objPs:ServicePetition;
        // Call
        public function AprobarPS(ter:String,idps:String,sec:int)
          servPs = new ServicioVPeticionesServicio();
          respPs = new CallResponder();
          respPs.addEventListener(ResultEvent.RESULT,getDatosPs);
          respPs.addEventListener(FaultEvent.FAULT,error);
          respPs.token = servPs.getPeticionServicio(ter,idps,sec);
        // Get the data
        private function getDatosPs(resultEvent:ResultEvent):void
          objPs = respPs.lastResult as VPeticionesServicio;
          switch (obj.petitionType) { // Here I have a null exception
    I make the debug with the blazeDS tools and all the responses and call statements is Ok, and the service return the data always, but Flex only works the first time per execution.
    If I assign all the data field by field from lastResult to ServicePetition all works properly always, the first call, the second call, etc., but if I want to make the assignment, object to object, only works 1 time.
    any ideas?
    best regards,
    thx!

    sorry, copy-paste problem...
    switch (objPs.petitionType)
    I have been researching and I think that I know where (maybe...) is the problem.
    The object to serialize have another object inside. Could be this the problem at the time to des-serialize the object? Also, the object is very big, have around 40 fields, could be also a problem ?
    thanks!

  • ABAP Objects Casting error

    Hi,
    I have declared two classes with names, ZCL_ONE, ZCL_TWO.
    ZCL_TWO is inhering ZCL_ONE.
    Now i am using them in the se38 program.
    While i use it, Narrow casting is working fine, But widening casting is not working.
    It is throwing an exception or a dump if i do not catch an exception.
    <i>Code:</i>
    DATA: OBJ1 TYPE REF TO ZCL_ONE,
               OBJ2 TYPE REF TO ZCL_TWO.
    CREATE OBJECT OBJ1.
    OBJ2 ?= OBJ1.
    The above code is giving me dump. Any guesses about how to solve it.
    I am able to work with the Narrow casting.. which is below code.. It is working fine.
    DATA: OBJ1 TYPE REF TO ZCL_ONE,
              OBJ2 TYPE REF TO ZCL_TWO.
    CREATE OBJECT OBJ2.
    OBJ1 = OBJ2.
    How to resolve the error.
    Thanks in Advance.

    obj1 should be the super(inherited) class of obj2....while using widening cast....
    example:
    INTERFACE i1.
      DATA a1 TYPE ...
    ENDINTERFACE.
    INTERFACE i2.
      INTERFACES i1.
      ALIASES a1 FOR i1~a1.
      DATA a2 TYPE ...
    ENDINTERFACE.
    CLASS c1 DEFINITION.
      PUBLIC SECTION.
        INTERFACES i2.
    ENDCLASS.
    CLASS c2 DEFINITION INHERITING FROM c1.
      PUBLIC SECTION.
        METHODS m1.
    ENDCLASS.
    DATA: iref TYPE REF TO i2,
          cref TYPE REF TO c1.
    CREATE OBJECT iref TYPE c2.
    ... iref->a1 ...
    ... iref->a2 ...
    TRY.
      cref ?= iref.
      CALL METHOD cref->('M1').
      CATCH cx_sy_move_cast_error
            cx_sy_dyn_call_illegal_method.
    ENDTRY.
    Message was edited by:
            Muthurajan Ramkumar

  • Object Casting confusion

    Hello,
    I have two classes used in the insurance business. One is a Member, which is someone covered by insurance (eg. an Employee, Spouse, Dependent) and one is a Employee which is more specificly the person who actually has the insurance.
    I am reading records of a database and creating each record into a Member Object. My Employee object extends Member. I want to know put the business logic in my main method to determine which Members is an Employee, Dependent, or Spouse.
    I am explicitly casting down the hierarchy, which I thought was allowable. I even implemented Cloneable on the Member object to try to get it work. The compiler seems to be fine with it, but I keep getting a runtime error: "ClassCastException".
    I am trying to avoid extracting the information from Member and having to reassemble it into Employee by using inheritance. What am I missing?
    Thanks.
    public class Member implements Cloneable
         private Object ssn;
         private Object planNumber;
         private Object locationCode;
         private Object coverageType;
         private Object benefit;
         private Object hireDate;
         private Object retireDate;
         private Object lastName;
         private Object firstName;
         private Object middleInitial;
         private Object address;
         private Object city;
         private Object state;
         private Object zip;
         private Object dob;
         private Object doh;
         private Object relationship;
         private Object gender;
         private Object effectiveDate;
         private Object status;
         private Object order; //represents order in spreadsheet
         //setters
         public void setOrder(Object order) {this.order = order;}
         public void setSSN(Object ssn){this.ssn = ssn;}
         public void setPlanNumber(Object planNumber){this.planNumber =planNumber;}
         public void setLocationCode(Object locationCode){this.locationCode = locationCode;}
         public void setCoverageType(Object coverageType){this.coverageType=coverageType;}
         public void setBenefit(Object benefit){this.benefit=benefit;}
         public void setHireDate(Object hireDate){this.hireDate=hireDate;}
         public void setRetireDate(Object retireDate){this.retireDate = retireDate;}
         public void setLastName(Object lastName){this.lastName= lastName;}
         public void setFirstName(Object firstName){this.firstName=firstName;}
         public void setMiddleInitial (Object middleInitial){this.middleInitial=middleInitial;}
         public void setAddress(Object address){this.address = address;}
         public void setCity(Object city){this.city = city;}
         public void setState(Object state){this.state = state;}
         public void setZip(Object zip){this.zip=zip;}
         public void setDOB(Object dob){this.dob=dob;}
         public void setDOH(Object doh){this.doh=doh;}
         public void setGender(Object gender){this.gender=gender;}
         public void setEffectiveDate(Object effectiveDate){this.effectiveDate=effectiveDate;}
         public void setStatus(Object status){this.status=status;}
         public void setRelationship(Object relationship){this.relationship = relationship;}
         //getters
         public Object getSSN(){return this.ssn;}
         public Object getPlanNumber(){return this.planNumber;}
         public Object getLocationCode(){return this.locationCode;}
         public Object getCoverageType(){return this.coverageType;}
         public Object getBenefit(){return this.benefit;}
         public Object getHireDate(){return this.hireDate;}
         public Object getRetireDate(){return this.retireDate;}
         public Object getLastName(){return this.lastName;}
         public Object getFirstName(){return this.firstName;}
         public Object getMiddleInitial(){return this.middleInitial;}
         public Object getAddress(){return this.address;}
         public Object getCity(){return this.city;}
         public Object getState(){return this.state;}
         public Object getZip(){return this.zip;}
         public Object getDOB(){return this.dob;}
         public Object getDOH(){return this.doh;}
         public Object getGender(){return this.gender;}
         public Object getEffectiveDate(){return this.effectiveDate;}
         public Object getStatus(){return this.status;}
         public Object getOrder() {return order;}
         public Object getRelationship(){return relationship;}
    }//end class
    import java.util.*;
    public class Employee extends Member
         Employee()
         private Spouse spouse;
         private Dependent dependent;
         private ArrayList dependents;
         private static int numberOfDependents;
         public void setSpouse(Spouse spouse){this.spouse = spouse;}
         public Spouse getSpouse(){return this.spouse;}
         public Dependent getDependent(int n)
              dependent = (Dependent)dependents.get(n);
              return dependent;
         public void setDependent(Dependent dependent)
              ++numberOfDependents;
              this.dependent = dependent;
              this.dependents.add(dependent);
         public ArrayList getDependents()
              return dependents;
         public void setDependents(ArrayList dependents)
              this.dependents = dependents;
         public int getNumberOfDependents()
              return numberOfDependents;
    }//end class
    import java.util.*;
    //Employee objects can be selfstanding Employee(String SSN)
    //The Spouse and Dependent objects - e.g. Spouse(String SSN, e)
    public class InsuranceObjectDriver
    //     ****************** START MAIN **********************************     
         public static void main(String[] args)
              //Open connection and query table
              DatabaseObjects db = new DatabaseObjects("LIBRARY", "", "");     
              db.queryDb("Table1");
              ArrayList memberList = db.getAllRecords();
              Member member;
                   member = (Member)memberList.get(0);
                   if (member.getRelationship().equals("E"))
                        Employee e =(Employee) member;
                   }

    >
    I see nothing wrong with the casting, since Employee
    is a Member.
    My only assumption is that the actual instance of
    "member" is not an Employee...so check your
    getRelationship().equals("E") condition...it may give
    you true, where it should have been false.This is why I'm casting it explicity to a Employee
    For design-wise, I see Employee, Spouse, and
    Dependent are more of a Member role..and not a
    "Member" superclass. I don't understand what you are trying to tell me here. Member is the superclass. Employee, Spouse, and Dependent are subclasses of the Member, which is one of the problems. I have to explicity cast down the hierarchy.
    Plus, what's with all the
    "Object" in the Member class? I never seen anyone
    did this before.
    I understand that by defining the Member attributes
    as Object, you can
    set the underlying type to anything in the
    future...without having to change the code...but i
    think this is a bad idea (just my thought).I like it. It dummy proofs things a bit. The input files are often sloppy and bad, plus I really don't care to maipulate most of these fields, I just need to make sure they populate the objects.
    E.g. I build a quick and dirty application for non-techies, who don't pay attention to data types much (in my many experiences). I don't want the program to bomb out on Date of Hire (doh) because it was brought in through the JDBC connection as an Object and not a Date.
    Data is brought into the application from the resultset via a getObject(n) call. Why change it? I guess I could use wrapper classes for them but I can't see why right now, but will consider this when I figure out the casting issue.

  • Crazy!! Tree object Casting... Error

    I've created a Jtree, consisting of objects of type (String x, String y, String z), When i rename a leaf id like the first String "x" in the object to change accordingly and the rest to remain the same...
    I've used a TreeModelListener with the treeNodesChanged methods to listen for a rename and the below code to change it, But i keep getting the following:-
    java.lang.ClassCastException: java.lang.String
    // Code
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
    MObject obj = (MObject) node.getUserObject(); //error
    node.setUserObject(new MObject (obj.x, obj.y, obj.z));
    the casting works perfectly in other sections of the code just not here. please help Thx

    pl. giv code for ur MObject and node creation

  • Check allocation object casting

    Hi
    Is there some function to check an object data for possible cast.
    Ive this sheet code for exemple
    Object obj1;
    Object obj2;
    Object obj3;
    JTree tree;
    JMenu menu;
    // Normaly it's not possible to cast fromm menu to tree
    obj1 = (Object)tree;
    obj2 = (Object)menu;
    Now i would like to check the real instance of the object
    ex :
    if obj1 is an instance of JTree
    do something
    else obj1 is an instance of JMenu
    do something else.
    The only solution to do this i've founded is use java.lang.ClassCastException
    Thanx for help

    Jeez, you were that close:
    if(obj instanceof JTree)
        // something
    else if(obj instanceof JMenu)
        // something else
    }Enjoy,
    Radish21

  • Java object casting

    hi, im just trying to get access to a method in an object in a linklist and cant seem to do it.
    the object is held in a link list and i can print its refrence easily but i want to access the getName function of that object but i cant seem to do it?????

    You use Class.forName("xxx") to get the Class object
    of your class stored in Linkedlist.That would be insane if you already have an object from the list.
    (If you want it's class do objectFromList.getClass()>
    Then you can invoke the method using Reflection.
    But since you know what type it is just cast it and call the method. JN_ has the right answer.
    Only use reflection if you don't know a class to cast to at compile time.

  • Object[] casting to String[] ERROR

    Hi! i have a LinkedBlockingQueue and by it's method .to Array() i want to cast it's type to String[] (it's initial is Object[])
    But i get a ClassCastException
    Help?

    An Object[] is not an String[] even if it only contains String objects: The content of the array does not define the type of the array, but the type of the array limits the possible types of the content.
    Look at the other .toArray() method that takes a parameter. If you put a String[] in, you get a String[] back out (you still have to cast, 'though, but then it will work).

  • Object Casting Issue

    This is Driving me Crazy!
    I have a method that Returns an Object
    Object myconfig = (Object)digester.parse("d:/siteconfig.xml");
    //Now, I always know in this case that the Object being returned
    //is always a "SiteConfig" object.
    //I know this for a fact I test that by doing object.GetClass().getName()
    //and I am looking at the debugger and it says that the object is a "SiteConfig" object
    //However for the life of me, I can not cast this object into a "SiteConifg" object even though it is. I get a ClassCastError Exception when I try to do..
    SiteConfig siteconifg = (SiteConfig)myconfig
    //Can anyone help me out?

    This is the stack trace...
    java.lang.ClassCastException
    at techone.groups.DigesterTest.doPost(DigesterTest.java:69)
    at techone.groups.DigesterTest.doGet(DigesterTest.java:34)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:260)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
    at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
    at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
    at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:432)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:386)
    at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:534)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:530)
    at java.lang.Thread.run(Thread.java:536)

  • Records and Objects, Cast for PL/SQL Type RECORD and SQL Type OBJECT

    Hi seniors:
    In my job, we have Oracle 10g, programming with Packages, the parameters are PL/SQL Types,
    Example:
    PACKAGE BODY NP_CONTROL_EQUIPMENT_PKG
    IS
    TYPE TR_EQUIPMENT_OPERATION IS RECORD(
    wn_npequipmentoperid CONTROL_EQUIPMENT.NP_EQUIPMENT_OPERATIONS.npequipmentoperid%TYPE,
    wv_npactiveservicenumber CONTROL_EQUIPMENT.NP_EQUIPMENT_OPERATIONS.npactiveservicenumber%TYPE,
    wv_npspecification ORDERS.NP_SPECIFICATION.npspecification%TYPE,
    wv_nptype ORDERS.NP_SPECIFICATION.nptype%TYPE,
    wn_nporderid CONTROL_EQUIPMENT.NP_EQUIPMENT_OPERATIONS.nporderid%TYPE,
    wn_npguidenumber CONTROL_EQUIPMENT.NP_EQUIPMENT_OPERATIONS.npguidenumber%TYPE,
    wd_npdevolutionprogramdate CONTROL_EQUIPMENT.NP_EQUIPMENT_STATUS.npdevolutionprogramdate%TYPE
    TYPE TT_TR_EQUIPMENT_OPERATION_LST IS TABLE OF TR_EQUIPMENT_OPERATION INDEX BY BINARY_INTEGER;
    PROCEDURE SP_GET_EQUIPMENT_OPERATION_LST(
    an_npequipstatid IN CONTROL_EQUIPMENT.NP_EQUIPMENT_STATUS.npequipstatid%TYPE,
    at_equipment_operation_list OUT TT_TR_EQUIPMENT_OPERATION_LST,
    av_message OUT VARCHAR2
    IS
    BEGIN
    SELECT EO.npequipmentoperid,
    EO.npactiveservicenumber,
    S.npspecification,
    S.nptype,
    EO.nporderid,
    EO.npguidenumber,
    ES.npdevolutionprogramdate
    BULK COLLECT INTO at_equipment_operation_list
    FROM NP_EQUIPMENT_OPERATIONS EO,
    NP_EQUIPMENT_STATUS ES,
    ORDERS.NP_ORDER O,
    ORDERS.NP_SPECIFICATION S
    WHERE EO.npequipstatid = ES.npequipstatid
    AND EO.nporderid = O.nporderid
    AND O.npspecificationid = S.npspecificationid
    AND EO.npequipstatid = an_npequipstatid;
    EXCEPTION
    WHEN OTHERS THEN
    av_message := 'NP_CONTROL_EQUIPMENT_PKG.SP_GET_EQUIPMENT_OPERATION_LST: '||SQLERRM;
    END SP_GET_EQUIPMENT_OPERATION_LST;
    END;
    Procedures calls other procedures and passing parameters IN OUT defined that PL/SQL Types. The problem appears when the access is through Java. Java can't read PL/SQL Types because only read SQL Types (Types defined in SCHEMA):
    CREATE OR REPLACE
    TYPE TO_EQUIPMENT_OPERATION AS OBJECT (
    wn_npequipmentoperid NUMBER,
    wv_npactiveservicenumber VARCHAR2(15),
    wv_npspecification VARCHAR2(8),
    wv_nptype VARCHAR2(2),
    wn_nporderid NUMBER,
    wn_npguidenumber NUMBER,
    wd_npdevolutionprogramdate DATE
    CREATE OR REPLACE
    TYPE TT_EQUIPMENT_OPERATION_LST
    AS TABLE OF "CONTROL_EQUIPMENT"."TO_EQUIPMENT_OPERATION"
    Java can read this SQL Types. The problem is how cast OBJECT to RECORD, because I can't execute that:
    DECLARE
    wt_operation_lst TT_EQUIPMENT_OPERATION_LST;
    BEGIN
    SELECT EO.npequipmentoperid,
    EO.npactiveservicenumber,
    S.npspecification,
    S.nptype,
    EO.nporderid,
    EO.npguidenumber,
    ES.npdevolutionprogramdate
    BULK COLLECT INTO wt_operation_lst
    FROM NP_EQUIPMENT_OPERATIONS EO,
    NP_EQUIPMENT_STATUS ES,
    ORDERS.NP_ORDER O,
    ORDERS.NP_SPECIFICATION S
    WHERE EO.npequipstatid = ES.npequipstatid
    AND EO.nporderid = O.nporderid
    AND O.npspecificationid = S.npspecificationid
    AND EO.npequipstatid = an_npequipstatid;
    END;
    and throws NOT ENOUGH VALUES, and I modified to:
    DECLARE
    wt_operation_lst TT_EQUIPMENT_OPERATION_LST;
    BEGIN
    SELECT TO_EQUIPMENT_OPERATION(EO.npequipmentoperid,
    EO.npactiveservicenumber,
    S.npspecification,
    S.nptype,
    EO.nporderid,
    EO.npguidenumber,
    ES.npdevolutionprogramdate)
    BULK COLLECT INTO wt_operation_lst
    FROM NP_EQUIPMENT_OPERATIONS EO,
    NP_EQUIPMENT_STATUS ES,
    ORDERS.NP_ORDER O,
    ORDERS.NP_SPECIFICATION S
    WHERE EO.npequipstatid = ES.npequipstatid
    AND EO.nporderid = O.nporderid
    AND O.npspecificationid = S.npspecificationid
    AND EO.npequipstatid = an_npequipstatid;
    END;
    Worst is that I can't modify this procedure and PL/SQL Types will survive.
    I have create a copy that CAST RECORD to OBJECT and OBJECT to RECORD too.
    PROCEDURE SP_COPY_PLSQL_TO_SQL(
    an_npequipstatid IN NUMBER,
    at_dominio_lst OUT ORDERS.TT_EQUIPMENT_OPERATION_LST, --SQL Type
    av_message OUT VARCHAR2
    IS
    wt_dominio_lst CONTROL_EQUIPMENT.NP_CONTROL_EQUIPMENT_PKG.TT_TR_EQUIPMENT_OPERATION_LST; --PL/SQL Type
    BEGIN
    SP_GET_EQUIPMENT_OPERATION_LST(an_npequipstatid, wt_dominio_lst, av_message);
    IF av_message IS NULL THEN
    at_dominio_lst := ORDERS.TT_EQUIPMENT_OPERATION_LST(ORDERS.TO_EQUIPMENT_OPERATION('','','','','','',''));
    at_dominio_lst.EXTEND(wt_dominio_lst.COUNT - 1);
    FOR i IN 1..wt_dominio_lst.COUNT LOOP
    at_dominio_lst(i) := ORDERS.TO_EQUIPMENT_OPERATION(wt_dominio_lst(i).wn_npequipmentoperid,
    wt_dominio_lst(i).wv_npactiveservicenumber,
    wt_dominio_lst(i).wv_npspecification,
    wt_dominio_lst(i).wv_nptype,
    wt_dominio_lst(i).wn_nporderid,
    wt_dominio_lst(i).wn_npguidenumber,
    wt_dominio_lst(i).wd_npdevolutionprogramdate
    END LOOP;
    END IF;
    END;
    I would like that the CAST is direct. Somebody can help me?. Thank you so much!

    I am facing the same problem as u had...may I know how u solved ur probkem...
    thanks,
    kishore

Maybe you are looking for

  • Automatic Refresh when site is changed

    After the great service on another question, I thought I would pose my next. i have been using the Blog page on Iweb to be able to inform users of latest news. The problem is when the link is clicked to take them there, they generally get the old pag

  • Virtual Private Database and BC4J

    How do I designate CLIENT_IDENTIFIER in Global Application Context on the database using BC4J ?

  • Accidentally Erased Mailbox, Problem With Recovery, Am DESPERATE FOR HELP!!

    I won't bore everyone with the specifics, but I accidentally deleted a mailbox containing tons of emails. I only realized this about an hour later... didn't do too much between the act and the realization. I immediately shut down the Mac, got another

  • New Member with popout menu problem

    I'm new to Dreamweaver and am trying to create a page of 3 frames that contains a dropdown/pop-out menu in the 2nd frame. When the popout exceeds 3 choices, it it no longer displayed, giving the user the sense that it "disappears" behind the main fra

  • Applet without browser

    Hi How do i execute applets without using a browser or the appletviewer . Basically i want to develop an application using applets only . The application will not have any browsers. Is this possible . If yes how ?. Regards Ajoy