Method accessing by reflection

Hi guys,
I am using ValueHolder Indirection, but my attributes must be private and I don't know what should be the signature of the accessor methods that toplink will try to find by reflection.
Does TopLink try to guess the method signature based on the attribute name and type?
Example: private ValueHolderInterface userType;
-> public void setUserType(ValueHolderInterface) and public ValueHolderInterface getUserType()
I looked at http://www.oracle.com/technology/products/ias/toplink/doc/1013/main/_html/mapcfg003.htm#CEGDDEEA but I couldn't find out if I would be obliged to specify what would be the accessor methods.

TopLink uses reflection to access private variable. Since TopLink is not really creating new objects as the application does, but really resorting the state of previously existing objects similar to Java serialization it normally makes sense for it to be using direct variable access, as this typically avoids undesired side effects that get/set method may contain.
However, using variable versus method access is completely up to you, TopLink supports both. To use method access you must supply the get/set method names to the mapping, TopLink does not guess these, although the Mapping Workbench will fill these in for you if you select method access for the project default. For mappings using ValueHolder indirection you must provide get/set methods that return/set the ValueHolderInterface, not its value. Or you can use direct variable access for these.

Similar Messages

  • Using ValueHolder Indirection With Method Accessing

    I am trying to use method getters/setters with value indirection member as described in the documentation
    (http://download-east.oracle.com/docs/cd/B31017_01/web.1013/b28218/mapcfg.htm#CEGFHCJF).
    My code modifies the mapping with the following lines:
    SessionFactory sf= LocatorLocator.getPersistence().getSessionFactory();
    Session s= sf.acquireUnitOfWork();
    ClassDescriptor d= (ClassDescriptor)s.getDescriptors().get(CharterBusTripLeg.class);
    DatabaseMapping m= d.getMappingForAttributeName("scheduledStartingLocation");
    m.setGetMethodName("getScheduledStartingLocationHolder");
    m.setSetMethodName("setScheduledStartingLocationHolder(oracle.toplink.indirection.ValueHolderInterface)");
    The CharterBusTripLeg class has the following members:
    private ValueHolderInterface scheduledStartingLocation;
    public Location getScheduledStartingLocation();
    public void setScheduledStartingLocation(Location scheduledStartingLocation);
    public ValueHolderInterface getScheduledStartingLocationHolder();
    public void getScheduledStartingLocationHolder(ValueHolderInterface scheduledStartingLocationHolder);
    When I try to restore an instance of CharterBusTripLeg, I get the following Exception:
    java.lang.NullPointerException
         at oracle.toplink.internal.security.PrivilegedAccessController.getMethodParameterTypes(PrivilegedAccessController.java:394)
         at oracle.toplink.internal.descriptors.MethodAttributeAccessor.getSetMethodParameterType(MethodAttributeAccessor.java:86)
         at oracle.toplink.internal.descriptors.MethodAttributeAccessor.setAttributeValueInObject(MethodAttributeAccessor.java:152)
         at oracle.toplink.mappings.DatabaseMapping.setAttributeValueInObject(DatabaseMapping.java:1119)
         at oracle.toplink.mappings.DatabaseMapping.readFromRowIntoObject(DatabaseMapping.java:1022)
         at oracle.toplink.internal.descriptors.ObjectBuilder.buildAttributesIntoObject(ObjectBuilder.java:244)
         at oracle.toplink.internal.descriptors.ObjectBuilder.buildObject(ObjectBuilder.java:525)
         at oracle.toplink.internal.descriptors.ObjectBuilder.buildObject(ObjectBuilder.java:381)
         at oracle.toplink.internal.descriptors.ObjectBuilder.buildObjectsInto(ObjectBuilder.java:677)
         at oracle.toplink.internal.queryframework.DatabaseQueryMechanism.buildObjectsFromRows(DatabaseQueryMechanism.java:142)
         at oracle.toplink.queryframework.ReadAllQuery.executeObjectLevelReadQuery(ReadAllQuery.java:483)
         at oracle.toplink.queryframework.ObjectLevelReadQuery.executeDatabaseQuery(ObjectLevelReadQuery.java:811)
         at oracle.toplink.queryframework.DatabaseQuery.execute(DatabaseQuery.java:620)
         at oracle.toplink.queryframework.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:779)
         at oracle.toplink.queryframework.ReadAllQuery.execute(ReadAllQuery.java:451)
         at oracle.toplink.publicinterface.Session.internalExecuteQuery(Session.java:2073)
         at oracle.toplink.publicinterface.Session.executeQuery(Session.java:988)
         at oracle.toplink.internal.indirection.QueryBasedValueHolder.instantiate(QueryBasedValueHolder.java:62)
         at oracle.toplink.internal.indirection.QueryBasedValueHolder.instantiate(QueryBasedValueHolder.java:55)
         at oracle.toplink.internal.indirection.DatabaseValueHolder.getValue(DatabaseValueHolder.java:61)
         at oracle.toplink.internal.indirection.UnitOfWorkValueHolder.instantiateImpl(UnitOfWorkValueHolder.java:148)
         at oracle.toplink.internal.indirection.UnitOfWorkValueHolder.instantiate(UnitOfWorkValueHolder.java:217)
         at oracle.toplink.internal.indirection.DatabaseValueHolder.getValue(DatabaseValueHolder.java:61)
         at oracle.toplink.indirection.IndirectList.buildDelegate(IndirectList.java:202)
         at oracle.toplink.indirection.IndirectList.getDelegate(IndirectList.java:359)
         at oracle.toplink.indirection.IndirectList.size(IndirectList.java:703)
         at test.com.laidlaw.les.charter.charter.DeleteBusTest.checkLegs(DeleteBusTest.java:55)
         at test.com.laidlaw.les.charter.charter.DeleteBusTest.testAddBus(DeleteBusTest.java:79)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    Any suggestions as to what I am doing wrong?
    thanks,
    chas

    Chas,
    You only need to set the method name without parameters.
    m.setSetMethodName("setScheduledStartingLocationHolder");Since these methods will typically only be used by TopLink you can make them protected or private.
    Doug

  • Configuring Method Accessing

    How do you turn Method Accessing on for all Entities using Java?
    I came across this thread which mentions <uses-method-accessing> in an XML file:
    Re: An interesting TOPLINK-6044
    However, is it possible to do this via an annotation or some configuration in the persistence.xml. I want to use Method Accessing at all times for all entities. Is this possible and is it possible to configure this via annotations or in persistence.xml.

    Thanks for the reply. I tried that and it seems to work. But if I have a transient field in my entity bean and specify method level annotations, TopLink tries to map even the transient field to a table column which is undesirable.
    I also tried annotating the getter methods for the fields I wanted Method Access on and leaving the fields I didn't care about at field-level annotations. But even that resulted in the transient field getting mapped to a database column.
    Any ideas?

  • Method access question

    I have a object which has been declared and created via another class. Is it possible to access another object and its methods in the "parent" class?
    Looking at the java API i thought maybe getClass().getDeclaringClass().myMethod() might work, but getClass().getDeclaringClass() returns null. I havent been able to find anything on the internet regarding this. I wouldnt think it would be an uncommon thing to want to do?...Any ideas? Cheers in advance...Nick

    Thanks for the suggestion. I actually tried this method (passing a reference to the constructor) in a previous project, but i thought maybe there was an easier way (Is this the usual way to tackle this kind of problem?). However, trying to use it in this one leads to more troubles. My instance of class1 is created when a button is clicked, through a buttonListener inner class in my MainWindow class. So what happes is that when i try to use
    Class1 = new Class1(this);instead of passing a reference to MainWindow, it passes a reference to buttonListener instead. This may be where i was on the right track because i then tried
    Class1 = newClass1(getClass().getEnclosingClass());i think i tried using getDeclaringClass() aswell and both would return null. Am i doing this right?

  • Method access problem

    I am creating a jsp web page to display the items to add to a shopping cart
    I am getting the following error message error message when i try
    to run may jsp display page i dont know what I have to do to get this working
    I am running Tomcat 5, Any help would be appreciated.
    The method addProduct(Product) in the type ShoppingCart is not applicable for the arguments (Product)
    Jsp page code snippet
    <jsp:useBean id="sCart" type="ShoppingCart" scope="session"/>
    <%@ page import="be.Product" %>
    <%@ page import="be.ShoppingCart" %>
    <% String featureTitle = request.getParameter("FeatureTitle");
       if(featureTitle!=null)
              String featureID = request.getParameter("FeatureID");
              String date = request.getParameter("Date");          
              String featureDescription = request.getParameter("FeatureDescription");
              String author = request.getParameter("Author");
              double price = Double.parseDouble(request.getParameter("Price"));
              Product newProduct = new Product(featureID, date, featureTitle, featureDescription, author, price);
              sCart.addProduct(newProduct);
    %>shopping cart class code snippet
    Vector products = new Vector();
         public void addProduct(Product i)
              boolean productFound = false;
              Enumeration productEnum = getProducts();
              while(productEnum.hasMoreElements())
                   Product product = (Product)productEnum.nextElement();
                   if(product.getId().equals(i.featureID))
                        productFound = true;
                        product.quantity += 1;
                        break;
              if (!productFound)
                   products.addElement(i);
         }product class code snippet
    public class Product
         String featureID, featureTitle, featureDescription, author, date;
         int quantity = 1;
         double price, total;
         public Product(){}
         public Product(String newid, String newdate, String newtitle, String newdescription, String newauthor, double newprice)
              this.featureID = newid;
              this.date = newdate;
              this.featureTitle = newtitle;
              this.featureDescription = newdescription;
              this.author = newauthor;
              this.price = newprice;
         }

    Hi,
    Well there are several notes on the service marketplace addressing problems with access method "G" like note 821519, 841175, 868913 and 901244.
    However regardless of the problem it is always recommended to use the newest sap kernel (Backend), be on the highest support package level (Backend), and off curse on newest patch level of the SAP GUI (Frontend).
    So try check the notes, and the notes related to them, check the kernel level of your backend, and the patchlevel of you GUI.
    Regards
    Rolf

  • Dynamic method call needs reflection class?

    Hi,
    First of all, this is my first post so go easy on me ;)
    I would like to have something like this in Java:
    String name = "number1";
    int temp = name + getme();
    the integer temp should now be the result of the method "number1getme()".
    By changing the value of 'name' I could get the value of number2, number3 etc. etc.
    Hope you understand and can help.
    Yours Sincerely,
    GrandiJoos

    If you really want to do it this way, you will indeed need to use reflection. Have you considered other options, such as storing values in a Map or creating one getme() method that takes a name argument?Map<String, Integer> temps = new HashMap<String, Integer>();
    .. fill the map with temperatures
    String name="number1";
    int temp = temps.get(name);orString name="number1";
    public int getme(String name) {
    int result = ...;
    if(name.equals("number1")) {
      result = <some temp here>;
    return result;
    }

  • Method accessibility design issues

    I have an application with many classes in different packages that have get/set methods for proprieties. I need to make other classes in different packages to have access to both get and set methods and other classes in one package (loaded with the class loader) to have access only to the get methods.
    What would be a good design for restricting access only to the setters for any class from that package but still provide the get method ? Right now there are some intermediary classes used and I think it's a bad design.
    Any suggestions ? Is there an utility to hide a public method from classes in a certain package ? I have a few ideas but they don't appeal to me more than the current design.

    I have an application with many classes in different
    packages that have get/set methods for proprieties. I
    need to make other classes in different packages to
    have access to both get and set methods and other
    classes in one package (loaded with the class loader)
    to have access only to the get methods.
    What would be a good design for restricting access
    only to the setters for any class from that package
    but still provide the get method ? Right now there
    are some intermediary classes used and I think it's a
    bad design. The bad design is that there are "many" getters and setters. Excluding DTO usage excessive exposure of data suggests both of the following
    - Code does not actually represent objects
    - Very tight coupling.
    Other than that then the use of intermediate classes (presumably nothing more than proxies) would be exactly the correct approach. Now if they aren't really proxies then that could be a problem.

  • Method access$0() and Interfaces doubts

    Hello All,
    I am working on a class browser, I have created one and it works successfully to a certain extent. But The class which I am having a Demo for a Tree Implementation in GUI, has a method called access$0() which I guess is automatically created on runtime by the super classes or somewhere, please let me know how and where can I get more details about this method.
    Also If my class under inspection is implementing one or more interfaces, how can I access its method names and variables.
    Also One more question, does Java maintain a list of sub-class information for each class somewhere.. just like Small Talk or it doesn't?? Please explain.
    Thanks,
    Sirish

    access$ methods are widely used to access private
    members of enclosing class from its inner class and
    vice-versa. These methods are generated by Java
    compiler, not by JVM runtime.
    See
    http://java.sun.com/docs/books/jvms/second_edition/htm
    l/ClassFile.doc.html#80128 for more details about
    synthetic class members.
    Other questions need more clarification.I will check that link, Regarding the other two questions:
    2. What I meant in my interfaces question is that... Say I have a class X that Extends Y and implements A,B
    Then if I want to display all the methods and fields of these classes and interfaces in a recursive way, till I reach the Object class, by going to superclass every time, then I understand I can get to class Y simple by
    using x.getSuperClass()
    but how can I get the interface methods?? and go upwards in that hierarchy??
    3. Sub class question is like this - Say I have 3 classes all user defined in the same directory Class A,B,C where A is the superclass of B and C. My class browser is displaying the hierarchy details of A, then is there any way to put in the details of B and C in the same hierarchical display or just display a separate list of subclass that this class has. I am not sure whether I have made it clear still.
    (I didnot understnad your reply on changing the class path, can you please explain it in a bit more detail, provided it holds for this question.)
    Regards,
    Sirish

  • Getting Method objects without reflection

    This is a shameless plug to try to get votes for a recent bug I've filed:
    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6356762
    For a long time, it's bothered me that there is no way other than reflection to obtain Method and Field objects to identify components of classes. It should be possible to write something like MyClass.class.nameOfMyField to obtain the FIeld object directly. With the current reflection-only method, one has to obtain these by looking up their String names. So:
    -there's no way for the compiler to detect syntax errors at compile time
    -no real way to obfuscate this code
    -debugging is more difficult because you are working indirectly through strings
    -it's inelegant to use Strings to perform at runtime what the compiler should be able to do at compile time
    One of the most immediate uses for this could be with classes conforming to the Beans pattern. Instead of specifying String names directly when firing property change events (whilch always risks a typo cauing a hard to trace error), you could obtain the coresponding Field object and call getName() on it.
    If something like this could be provided in Mustang, I would be in seventh heaven. Please vote for the bug, or let me know what you think about this.

    I would definately have usage of that. I've always loved function pointers in C, and jump tables in assembler.
    Kaj

  • Web Service method to merge reflection

    Hi,
    Is there any P6 web service method available to update Project from reflection  ?
    We can create reflection from project using operation CopyProjectAsReflection available in ProjectService.
    But how to merge this reflection to the project?
    Thanks,
    Abhi

    Hi,
    Is there any P6 web service method available to update Project from reflection  ?
    We can create reflection from project using operation CopyProjectAsReflection available in ProjectService.
    But how to merge this reflection to the project?
    Thanks,
    Abhi

  • Method definition with reflection doesn't show Exceptions

    According to the documentation, http://java.sun.com/j2se/1.4.1/docs/api/java/lang/reflect/Method.html#toString(), returns checked exceptions. I don't know about checked exceptions, but the following code doesn't give me any exceptions:
    final Class[] parameters = {
       Class.forName("java.util.Collection")
    Method method = Class.forName("java.util.ArrayList").getDeclaredMethod("addAll", parameters);
    System.out.println(method.toString());Instead, I just get public boolean java.util.ArrayList.addAll(java.util.Collection)But addAll throws IndexOutOfBoundsException and NullPointerException - see http://java.sun.com/j2se/1.4.1/docs/api/java/util/ArrayList.html#addAll(java.util.Collection).
    Umm... I'm puzzled, and any help would be very appreciated!

    But addAll throws IndexOutOfBoundsException and NullPointerException Which are unchecked or runtime exceptions, not checked exceptions.
    Runtime exceptions are not declared in Java throws clauses, though they may be mentioned inthe API docs. They inherit from the RuntimeException class.
    Checked exceptions must be declared in the Java throws clause, and are subclasses of Exception which are not subclasses of RuntimeException. The compiler checks that checked exceptions are caught or declared by the calling method, hence the name.
    Pete

  • Extensions/Method Access

    right. i have a class "1" which extends an abstract class "2" which extends an abstract class "3." hence, class "1" implements all methods in classes "2" and "3" along with a few of its own. the constructor in a fourth class, is parsed a new instance of class "1" (of type "class 3"), how can i access all the methods in class "1" using this fourth class? i have tried using for example:
    instancename.but the only methods i can access are the ones in the super class (i.e. class "3"

    chris,
    All humans are mammals.
    Are all mammals human?
    mouse.think keeps returning IHateCatsException.
    keith.

  • Methods Accessing quesstion

    Hi all ,
    my application can work with several db back-ends (MySQL,ORacle ...)
    so the structure at high level has the following 3 layers:
    GUI - Intermediate DB class - MySQL DB classes, Oracle DB classes ...
    My Intermediate DB class , depending on a .ini variable, selects the appropiate MYSQL or Oracle method
    How can I avoid accessing to MySQL/Oracle methods directly from the GUI without passing through the intermediate class?
    MySQL and Oracle methods are in different .java...
    Thanks!

    So, if I well understood, the intermediate layer
    should be an interface and MySQL_DB_methods and
    ORacle_DB_methods should implement these methods isnt
    it?
    E.g. MySQL_DB_methods.createNewUser(UserBean user)
    Oracle_DB_methods.createNewUser(UserBean user)
    but this method createNewUser should be public isnit?
    so I can access also from GUI which is the situation
    i want to avoid ....
    Thanks!No. Why bother with these RDBMS-specific methods at all? JDBC doesn't do that, so why do you? The point Rene is making is, your UI layer should not be aware of the underlying data access technology, this is the essence of the DAO pattern. You seem to be going to some lengths to couple your app. to a particular database, whereas everyone else in the world goes in the other direction

  • Method access

    I am creating a jsp web page to display the items to add to a shopping cart
    I am getting the following error message error message when i try
    to run may jsp display page i dont know what I have to do to get this working
    I am running Tomcat 5, Any help would be appreciated.
    The method addProduct(Product) in the type ShoppingCart is not applicable for the arguments (Product)
    Jsp page code snippet
    <jsp:useBean id="sCart" type="ShoppingCart" scope="session"/>
    <%@ page import="be.Product" %>
    <%@ page import="be.ShoppingCart" %>
    <% String featureTitle = request.getParameter("FeatureTitle");
       if(featureTitle!=null)
              String featureID = request.getParameter("FeatureID");
              String date = request.getParameter("Date");          
              String featureDescription = request.getParameter("FeatureDescription");
              String author = request.getParameter("Author");
              double price = Double.parseDouble(request.getParameter("Price"));
              Product newProduct = new Product(featureID, date, featureTitle, featureDescription, author, price);
              sCart.addProduct(newProduct);
    %>shopping cart class code snippet
    Vector products = new Vector();
         public void addProduct(Product i)
              boolean productFound = false;
              Enumeration productEnum = getProducts();
              while(productEnum.hasMoreElements())
                   Product product = (Product)productEnum.nextElement();
                   if(product.getId().equals(i.featureID))
                        productFound = true;
                        product.quantity += 1;
                        break;
              if (!productFound)
                   products.addElement(i);
         }product class code snippet
    public class Product
         String featureID, featureTitle, featureDescription, author, date;
         int quantity = 1;
         double price, total;
         public Product(){}
         public Product(String newid, String newdate, String newtitle, String newdescription, String newauthor, double newprice)
              this.featureID = newid;
              this.date = newdate;
              this.featureTitle = newtitle;
              this.featureDescription = newdescription;
              this.author = newauthor;
              this.price = newprice;
         }

    access$ methods are widely used to access private
    members of enclosing class from its inner class and
    vice-versa. These methods are generated by Java
    compiler, not by JVM runtime.
    See
    http://java.sun.com/docs/books/jvms/second_edition/htm
    l/ClassFile.doc.html#80128 for more details about
    synthetic class members.
    Other questions need more clarification.I will check that link, Regarding the other two questions:
    2. What I meant in my interfaces question is that... Say I have a class X that Extends Y and implements A,B
    Then if I want to display all the methods and fields of these classes and interfaces in a recursive way, till I reach the Object class, by going to superclass every time, then I understand I can get to class Y simple by
    using x.getSuperClass()
    but how can I get the interface methods?? and go upwards in that hierarchy??
    3. Sub class question is like this - Say I have 3 classes all user defined in the same directory Class A,B,C where A is the superclass of B and C. My class browser is displaying the hierarchy details of A, then is there any way to put in the details of B and C in the same hierarchical display or just display a separate list of subclass that this class has. I am not sure whether I have made it clear still.
    (I didnot understnad your reply on changing the class path, can you please explain it in a bit more detail, provided it holds for this question.)
    Regards,
    Sirish

  • Method access vs variable access

    Why would one use a private variable and have get and set methods that change its value instead of simply allowing direct access by making the variable public?

    Ok I've semi-sobered up and here's a better example
    suppose you've developed a client-server application and for some reason the contractor that did the server class hardcoded the port number as public int portnumber =6667; and was subsequently fired for tap dancing on the CIO's desk.
    In theory I can write something like this
    setportNumber(myServerObj obj)
    obj.portnumber = 80;
    }which if your application is supporting large amounts of users then you'll either be paid over time to fix it or fired for allowing the contractor to do it in the first place..

Maybe you are looking for