Primitives and wrappers

int i=10;
Integer I=50;
System.out.println(Integer.class.isInstance(i)); // prints true
System.out.println(int.class.isInstance(I)); // prints false
System.out.println(Integer.class.isAssignableFrom(int.class)); // prints false
System.out.println(int.class.isAssignableFrom(Integer.class)); // prints falseThe problem:
I have two classes (not objects) at runtime. One is supposed to be for a primitive (ex. int.class) and the other is for its wrapper (Integer.class). I need to validate that both classes ara compatible (assignable to each other). The only statement above that returns true I cannot use because it accepts an object as a parameter which I don't have.
Thank you

If there were int.class, this example would compile and work:
C:\doku>java testVersion
false
true
false
true
false
false
public class testVersion
  public static void main( String args[] ) throws Exception
    System.out.println( okay( int.class, Short.class ) );
    System.out.println( okay( int.class, Integer.class ) );
    System.out.println( okay( int.class, Long.class ) );
    System.out.println( okay( short.class, Short.class ) );
    System.out.println( okay( short.class, Integer.class ) );
    System.out.println( okay( short.class, Long.class ) );
  static boolean okay( Class pri, Class obj )
    java.lang.reflect.Constructor[]     ct = obj.getConstructors();
    for ( int i = 0; i < ct.length; i++ )
      Class[]   params = ct[ i ].getParameterTypes();
      if ( 1 == params.length && params[ 0 ] == pri )
        return true;
    return false;
}

Similar Messages

  • ArrayList and wrappers

    Can an ArrayList contain different types of objects from the same class?
    I know that it must be an object but can one be of type String and another be of type int?
    I am reading information from a file that looks something like this:
    Sam
    Jones
    21
    Tim
    Hendricks
    15
    I have written the following method:
    ArrayList list = new ArrayList();
    String fname;
    try
      BufferedReader br = new BufferedReader(new FileReader("student.txt"));
      while ((fname = br.readLine()) != null)
             String lname=br.readLine();
         int age= br.readLine();
         br.readLine(); //FOR THE BLANK LINE
         list.add(new Student(fname, lname, age));
      br.close();
    catch(IOException e)
      System.err.println(e.getMessage());
      System.exit(0);
    }If I declare age as type String the method and other methods work great, but I need to make it of type int.
    I have read up about wrappers and I think that is what I am suppose to use for the int but no matter what I do, I get tonnes of error messages.
    Any help would be appreciated.

    A better way would be to build a class for your data packet.
    class Thing {
      public final String name;
      public final int age;
      public Thing(String name, int age) {
        this.name = name;
        this.age = age;
    public class SomeClass {
      public static void main(String[] args) {
        List list = new ArrayList();
        list.add(new Thing("Jill",10));
        list.add(new Thing("John",20));
        list.add(new Thing("Janet",30));
        list.add(new Thing("Jeremy",40));
    }Then you can simply get your values back with
    for(Iterator iterator = list.iterator(); iterator.hasNext(); ) {
      Thing thing = (Thing) iterator.next();
      System.out.println("Name: "+thing.name);
      System.out.println("Age: "+thing.age);
    }Or something like that...
    Talden

  • Generics, Primitives, and Lightweight Objects

    One of the planned features for JDK 1.5 is autoboxing of primitives. Basically, treat primitives like objects.
    My big question: Are the generics and primitives ideas being reconciled?
    Speaking of primitives, David Bacon created a Java dialect called Kava (see link below). Briefly, it's precisely what I want inJDK 1.5.
    "Kava: A Java dialect with a uniform object model for lightweight classes"
    David F. Bacon, IBM T. J. Watson Research Center
    http://aspen.ucs.indiana.edu/CandCPandE/jg2001/C559bacon/c559Bacon02Kava.pdf

    Speaking of primitives, David Bacon created a Java
    dialect called Kava (see link below). Briefly, it's
    precisely what I want inJDK 1.5.I think you will be disappointed --- I would be very surprised if anything so radical was considered.

  • Primitives and garbage collector

    Hi everyone,
    Do primitives get garbage collected?
    Is it recommended to set all references to null in a classes finalize method?
    Thanks

    Do primitives get garbage collected?No.
    Is it recommended to set all references to null in
    in a classes finalize method?No, there is no point in doing that.

  • Equality between primitive and persistent objects

    Folks,
    I have discovered by chance that the KODO Query implementation allows me
    to test for equality between an Integer and a persistent object. This is
    actually phenomenally useful because it allows me to easily work around
    some really inefficient auto-generated SQL (see below).
    I couldn't find anything about this feature in the JDO specs. Is it
    accidental? Is it supported, or likely to disappear in future versions?
    Dave Syer.
    # 'bean' is an object already loaded from the persistence store
    javax.jdo.JDOHelper.getObjectId(bean)Bean-101
    # it has one mutable property, which is persistence capable
    # and also a read-only property which is the database id
    # (Integer) of the property:
    javax.jdo.JDOHelper.getObjectId(bean.getProperty())Property-371
    bean.getPropertyId()371
    # get an extent for querying (pm is the PersistenceManager)
    ex=pm.getExtent(Bean,0)# First do a query on property...
    qu=pm.newQuery(ex);
    qu.declareParameters("Property id1");
    qu.setFilter("property == id1")# ...generates SQL with additional unnecessary(?) Cartesian join
    # to PROPERTY table:
    res=qu.execute(bean.getProperty())# resulting SQL:
    # SELECT t0.PROPERTY_ID, t0.PROPERTY_ID FROM BEAN t0, PROPERTY t1
    # WHERE (t0.PROPERTY_ID = 371 AND t0.PROPERTY_ID =
    # t1.PROPERTY_ID)
    # Now do a query on propertyId (Integer)...
    qu=pm.newQuery(ex);
    qu.declareParameters("java.lang.Integer id1");
    qu.setFilter("propertyId == id1")# ...but parameter value is allowed to be a Property -- magically
    # turned into an integer when the SQL is generated:
    res=qu.execute(bean.getProperty())# resulting SQL:
    # SELECT t0.PROPERTY_ID, t0.PROPERTY_ID FROM BEAN t0 WHERE
    # t0.PROPERTY_ID = 371

    It is accidental and unsupported.Is there any other way to get round the 'unnecessary join' issue that I
    mentioned briefly in my original posting? In a real world example, I was
    able to improve performance of a single query by a factor of 100 (and my
    DB experts tell me there was no way to optimise indexes or anything at the
    RDBMS level and achieve the same result).
    DAve.

  • C++ primitive versus Coherence Primitive POF encoding

    I was wondering if anyone can shed some light on the differences b/w POF encoding of C++ primitives vs encoding of Coherence Primitive.
    I've noticed using Coherence Primitives retain both type & value allowing readObject() to work as expected, whereas there are nuances where only the value is retained when using primitives.
    * Is there an inherent difference as to how primitive types are POF encoded versus Coherence Primitives ? ie. Do they both use packed optimizations? Are Coherence Primitives encoded as a Type which contains the primitive type, or are they both encoded the same.
    * Is it possible for readObject() to infer the correct types from the stream, or must the type definition always be implicit. ie. The deserializer and serializer must always agree on read/write methods. How is readObject() affected by the optimizations?
    * The return type and name of the function readObject() implies it only deals with objects, but its documentation states it reads a property of ANY type including a user type from the stream. How does it internally handle primitive types? ie. If it encounters a primitive in the stream, does readObject() wrap it in a (correct) Coherence Primitive?
    * Is there any cross-language implications when using Coherence Primitives?

    Hi Mark,
    For those who may be confused by what a "Coherence Primitive" is I'll clarify. The coherence::lang::Primitive<T> template class is a common template base class used for building up wrapper classes for C++ primitive types such as bool, int32_t, int64_t. For instance the coherence::lang::Integer32 class extends Primitive<int32_t>, and works similar to the relationship between int and java.lang.Integer in Java. Primitive<> extends from coherence::lang::Object class which is the root of our manage object class hierarchy. As with Coherence for Java these primitive wrappers are POF serializable. In fact the description I give here applies equally to our Java and C++ extend clients.
    Language primitives and primitive wrappers are bit for bit identical when serialized in POF format. There is however a subtle but important difference. For some values PofWriter may choose to entirely optimize out the value from the byte stream, and this does differ between the primitives and wrappers. The basic rule is that primitives can be optimized out of the POF stream entirely when writing the types default 'zero' value, and this is not true for the wrapper types. For instance:
    hWriter->writeInt32(PROP_ID_BLAH, 0); // this will be a noop
    This will be a noop, and the corresponding readInt32() call will treat the lack of a property in the POF stream as a zero value.
    int32_t nVal = hReader->readInt32(PROP_ID_BLAH); // will return 0
    However if you were to write out the corresponding wrapper object a zero would be written to the stream.
    hWriter->writeObject(PROP_ID_BLAH, Integer32::create(0)); // writes a zero to the stream
    Integer32::View vnVal = cast<Integer32::View>(hReader->readObject(PROP_ID_BLAH)); // will return an Integer32 representing zero
    This optimization works beautifully so long as the reader and writer are symmetric, using either the same type of methods for a given property. If you mix and for instance use writeInt32, and then readObject, you can see some surprising results. For instance zero's come out as NULLs, and all other numeric types (such as Integer64 or Float32/64) will come out as Integer32 for certain small numeric values. This has caused us some issues with the initial release of PofExtractor which always returns Objects, and as such will show behavior similar to the above when the primitive based writer methods were used during serialization. This fix for this specific issue will be made available soon in an upcoming 3.5 service pack.
    So this leaves the question what method should you use for writing primitives. I would say that in the vast majority of cases it would be preferable to use the primitive variants, rather then writing the wrapper object via writeObject(). The biggest advantage of this is that it avoids the unneeded object creation. The primary benefit of using writeObject() for the wrappers is that it gives you one additional value, i.e. NULL. So for instance which writeBoolean() can only communicate one of two values (true, false), writeObject() passing a Boolean, can communicate one of three values (true, false, NULL). Outside of that writeObject() on a primitive wrapper is also beneficial for generic code which doesn't know the type of the object being serialized.
    I suppose the docs for writeObject need some cleanup. This method supports the serialization of any type which extends from coherence::lang::Object, and has a registered POF serializer.
    To answer your final question the two variants produce language neutral POF streams, and can be read from Java and .NET just fine.
    hope that helps,
    Mark
    Oracle Coherence

  • Differences between primary types and wrapes

    Hi,
    I am developing an two applications that change information over RMI, i can use primitive types, like long, boolean, int or wrapes of primary types like Long, Boolean, Integer
    Beacuse both types are serializable, but i dont nkow what type must i use, somebody can explain me what is the best from the point of view of the performance and serialization????
    thanks

    The primitives, usually, unless you have a reason to use a wrapper.I would have said "...unless you absolutely have to." Autoboxing encourages the illusion that primitives and wrapper objects are interchangeable, and that's a dangerous illusion. Consider this example: import java.util.*;
    public class Test
      public static void main(String... args) throws Exception
        List<Integer> intList = Arrays.asList(1, 2, 300, 400);
        int a = 1;
        Integer b = 2;
        int c = 300;
        Integer d = 400;
        System.out.printf("%3d == %3d: %b%n", a, intList.get(0),
                          a == intList.get(0));
        System.out.printf("%3d == %3d: %b%n", b, intList.get(1),
                          b == intList.get(1));
        System.out.printf("%3d == %3d: %b%n", c, intList.get(2),
                          c == intList.get(2));
        System.out.printf("%3d == %3d: %b%n", d, intList.get(3),
                          d == intList.get(3));
    } Output:   1 ==   1: true
      2 ==   2: true
    300 == 300: true
    400 == 400: false In some cases, == is comparing two ints; in others, two objects. If you use primitives and wrappers interchangeably without appreciating the distinction, you'll never know which kind of comparison is being performed. To minimize the risk of this kind of bug, you should always declare primitive values as primitives, not as wrapper types.

  • Why Java not allowed Widening and auto-boxing in single expression?

    Hi All,
    I have a very small question in my mind, that I would like to put on this discussion board.
    Why Java not allowed Widening and auto-boxing in single expression?
    Like:
    short s = 10;
    Long l = s;I want to know if java allowed above expression then what problem may occur?
    I know it is not a intelligent question, However still I ask for discussion.
    Thanks advance for all viewer of this question.

    JoachimSauer wrote:
    jverd wrote:
    I didn't like it at first, but it turns out my initial complaints were pretty much unfounded. I find it quite useful. It takes a fair amount of clutter out of code. The only real problem with it is that if you're not careful, you can end up doing a lot of unnecessary bouncing back and forth between primitives and wrappers without knowing it, which could hurt performance.In my opinion the biggest problem is getting NPEs at code lines, that look completely harmless. That used to bother me too, but then, if I'm writing
    int i = getAnInteger();it's just a replacement for
    int i = getAnInteger().intValue();which would also have caused NPE.
    That is, if I'm using autoboxing properly, it's just shorthand for what I'd have been doing otherwise anyway. True, it's easy to not think about it, to forget to consider whether NPE is a possibility and what the proper approach is, but mostly, if I want int, I know it can't be null (or if it is, I should get NPE).
    And when it comes time to debug the NPE, it's no great mystery, once you know the rules.
    If you don't think of autoboxing at the right position, then you can spend hours after hours tracking down a trivial bug ... or so I've heard ;-)Even if you're not thinking about it when you write the code, when you see an "impossible" NPE during debugging, it should be an instant giveaway.

  • JTable custom renderer never calls getTableCellRendererComponent()

    I have a custom renderer for Dates in my JTable. I've set it as the renderer on Date columns and I've also tried setting it as the table default for the Date type. In both cases the getTableCellRendererComponent() method never gets called.
    I've also tried right-justifying String columns with
              DefaultTableCellRenderer renderer = (DefaultTableCellRenderer)table.getDefaultRenderer(String.class);
              renderer.setHorizontalAlignment(JLabel.RIGHT);
    but the Strings are always left-justified. Same with integers.
    I verify that the new renderer / alignments are actually set immediately after setting them. A few method calls later I notice that the alignments have changed back. My custom date renderer is still set, however.
    My code calls fireTableStructureChanged(). I set/reset all renderers after the call to fireTableStructureChanged(). I wonder if fireTableStructureChanged() rebuilds the table some teim later wiping out the renderer / alignments that I've set and replacing them with the defaults.
    Is there a callback or some method that I need to override after calling fireTableStructureChanged() in order to get my renderer / alignments to remain in effect?

    I can't post the code because it is proprietary and the application itself is large.
    The trouble seems to start when I call fireTableStructureChanged(). None of the toy examples in books that I've seen address fireTableStructureChanged(). The JavaDocs for Swing don't tell you about all of the side effects of fireTableSTructureChanged().
    You're comment about overriding getColumnClass() got my custom data renderer working. The Javadocs for DefaultTableModel and JTable don't mention when you need to override getColumnClass(). Overriding getColumnClass() in the TableModel seems to apply to JTable as well. I don't understand why, but it seems to work.
    I am able to justify my columns be creating a default renderer and calling setHorizontalAlignment() on it and setting it as the default for the JTable. The code below doesn't work, however:
    DefaultTableCellRenderer renderer = (DefaultTableCellRenderer)table.getDefaultRenderer(int.class);
    renderer.setHorizontalAlignment(JLabel.RIGHT);
    It seems that the default renderers reset themselves back to their default state. I have no idea why, but that is what I am seeing.
    There is also a big difference in the way that primitives and wrappers are handled (i.e. int compared to Integer).
    One of the other posters here said that if I call setModel() that I would have to reset the renderers. The Javadocs don't say anything about that. (I only call setModel during initialization. I do update the actual data in the TableModel which can change the structure of the table. That is when I call fireTableStructureChanged() and all the difficulties start.)
    This whole episode has shown that the Swing Javadocs are next-to-worthless for writing real-world Swing applications. I've written several Swing applications over the years, and once they get beyond the simple level they become difficult to write and maintain due to the lack of documentation. For my next Java GUI I'm going to check out JavaFX (as soon as it is available on Linux). I don't see how it could be worse than Swing.
    Thanks for all of your help. You got me on the path to getting this solved.

  • Object and reference accessing for primitives, objects and collections

    Hi,
    I have questions re objects, primitives and collection accessing and references
    I made a simple class
    public class SampleClass {
         private String attribute = "default";
         public SampleClass()
         public SampleClass(SampleClass psampleClass)
              this.setAttribute(psampleClass.getAttribute());
              if (this.getAttribute() == psampleClass.getAttribute())
                   System.out.println("INSIDE CONSTRUCTOR : same object");
              if (this.getAttribute().equals(psampleClass.getAttribute()))
                   System.out.println("INSIDE CONSTRUCTOR : equal values");
         public void setAttribute(String pattribute)
              this.attribute = pattribute;
              if (this.attribute == pattribute)
                   System.out.println("INSIDE SETTER : same object");
              if (this.attribute.equals(pattribute))
                   System.out.println("INSIDE SETTER : equal values");
         public String getAttribute()
              return this.attribute;
         public static void main(String[] args) {
    ...and another...
    public class SampleClassUser {
         public static void main(String[] args) {
              SampleClass sc1 = new SampleClass();
              String test = "test";
              sc1.setAttribute(new String(test));
              if (sc1.getAttribute() == test)
                   System.out.println("SampleClassUser MAIN : same object");
              if (sc1.getAttribute().equals(test))
                   System.out.println("SampleClassUser MAIN : equal values");
              SampleClass sc2 = new SampleClass(sc1);
              sc1.setAttribute("test");
              if (sc2.getAttribute() == sc1.getAttribute())
                   System.out.println("sc1 and sc2 : same object");
              if (sc2.getAttribute().equals(sc1.getAttribute()))
                   System.out.println("sc1 and sc2 : equal values");
    }the second class uses the first class. running the second class outputs the following...
    INSIDE SETTER : same object
    INSIDE SETTER : equal values
    SampleClassUser MAIN : equal values
    INSIDE SETTER : same object
    INSIDE SETTER : equal values
    INSIDE CONSTRUCTOR : same object
    INSIDE CONSTRUCTOR : equal values
    INSIDE SETTER : same object
    INSIDE SETTER : equal values
    sc1 and sc2 : equal values
    ...i'm just curios why the last 3 lines are the way they are.
    INSIDE SETTER : same object
    INSIDE SETTER : equal values
    sc1 and sc2 : equal values
    how come while inside the setter method, the objects are the same object, and after leaving the setter method are not the same objects?
    Can anyone point a good book that shows in detail how objects, primitives and collections are referenced, especially when passed to methods. Online reference is preferred since the availability of books can be a problem for me.
    Thanks very much

    You are confusing references with objects.
    This compares two object references:
    if( obj1 == obj2 ) { // ...Whereas this compares two objects:
    if( obj1.equals(obj2) ) { // ...A reference is a special value which indicates where in memory two objects happen to be. If you create two strings with the same value they won't be in the same place in memory:
    String s1 = new String("MATCHING");
    String s2 = new String("MATCHING");
    System.out.println( s1 == s2 ); // false.But they do match:
    System.out.println( s1.equals(s2) ); // trueIf you're using a primitive then you're comparing the value that you're interested in. E.g.
    int x = 42;
    int y = 42;
    System.out.println(x == y); // trueBut if you're comparing references you're usually more interested in the objects that they represent that the references themselves.
    Does that clarify matters?
    Dave.

  • How to use the substring and can i class method for the primitive type

    MY COMPILER
    public class StringLine
    public static void main(String[] args)
    String sentence;
    char letter;
    char name;
    int position;
    System.out.println("Enter a line of text. No punctuation please");
    sentence = MyIO.readLine();
    System.out.println("I have rephrase that line to read:");
    position = sentence.indexOf(" ");
    name = sentence.charAt(postion, position+ 1);
    name = name.toUpperCase();
    letter = sentence.charAt(0);
    letter = letter.toLowerCase();
    sentence = name + sentence.substring(position + 2)
              + letter + sentence.substring(1, position);
    //////////////// I got 3 errors following:
    StringLine.java:16: cannot resolve symbol
    symbol : variable postion
    location: class StringLine
    name = sentence.charAt(postion, position+ 1);
    ^
    StringLine.java:17: char cannot be dereferenced
    name = name.toUpperCase();
    ^
    StringLine.java:20: char cannot be dereferenced
    letter = letter.toLowerCase();
    ^
    3 errors
    }

    position = sentence.indexOf(" ");
    name = sentence.charAt(postion, position+ 1);
    name = name.toUpperCase(); two error here:
    1. as stated above postion is mispelled...should be position
    2. you cannot perform a chatAT(int, int)
    I think you want to perform a substring
    String name;  // should be a string instead of a char..(char is a primitive and all primitive have no method)
    position = sentence.indexOf(" ");  
    name = sentence.substring(position, position + 1).toUpperCase();
    [./code]
    better yet..you should check if the sentence does contain a spaceString name;
    position = sentence.indexOf(" "); // return a negative value if the search string is not part of the string
    if (position != -1)
    name = sentence.substring(position, position + 1).toUpperCase();
    else
    System.out.println("The sentence does not contain a space);
    [./code]
    String letter;
    letter = new String(sentence.charAt(0));
    letter = letter.toLowerCase();
    // or
    char letter;
    letter = sentence.toLowercase().charAt(0);

  • Logical Comparisons Of Wrappers

    Ok super easy question...so easy that it's not documented anywhere that I have searched so far...
    Is it proper to compare wrappers with logical operators (i.e. ==, !=)?
    Technically a wrapper is an object, so therefore the == operator would compare the memory address of the two objects to give you a boolean expression result. Meaning, this result is probably not the 'logically equivalent' result you were looking for. However, is it proper to compare a wrapper to a literal using these operators? For example...
    Integer i = new Integer(7);
    if (i == 7) {}or...
    if (i != 7) {}Is the wrapper implicitly cast? I have heard of something called autoboxing which says this might be the case, where the conversion from wrapper to primitive and vice versa is automated. Or, do I need to explicitly grab the int value from the wrapper for the comparison as such...
    if (i.intValue() == 7)or...
    if (i.intValue != 7)I have seen code in both forms in working applications. So which is correct, or more correct as the case may be? Is this something that is version specific? One question turned into many, sorry about that, but thanx for your responses. :D
    ~ Jester's Chef

    If you are using Java5.0 then you can use "if (i == 7)" because the compiler will handle getting the int vaule from i. (ie autoboxing)
    If you are using a version before Java5.0 you have to retrieve the int value from the Integer object and then do the comparison like "if (i.intValue() == 7)"
    So the answer depends on which version of Java you are using.

  • Jdev webservice and java.util.Collection

    Hi,
    i write a web service based on an stateless
    session EJB i have 2 method who return double
    and they work fine.
    But i have added a method who return a Collection and
    when i try to regenerate my web service i got
    a message error because the return type does not
    have an xml chema mapping and/or serializer
    specified.
    How can i fix this problem ?
    I use jdev 9.0.5.2 and oracle 9ias 9.0.4.1.
    Thank you for your help.

    I'm not a WS PM, but I think the problem here is that a java.util.Collection is a supported type for WS based on the 904 release. From what I remember the supported types are the Java primitives, their wrappers (ie java.lang.Long), java.lang.String, arrays of these and JavaBeans which have fields of these types.
    I think if you want to use Collections then you need to use the JAX-RPC enabled Web Services which we provide in the 10.1.3 releases of JDev and OC4J.
    cheers
    -steve-

  • Open images as float all in windows and not as uneditable background

    I hope the Elements team read these posts occasionally, and realize how many people want to default images to open "float all in windows" instead of having to hunt through the drop down menus to do it every single time PSE is opened. I also want to be able to open everything as an editable layer, rather than having to hunt through the menus every single time for the "new adjustment layer" command. Both of course were done by default by the supposedly primitive and inferior PhotoDeluxe I used on Windows...

    As for the adjustment layers, you can do that right from the layers panel:
    Just click the black and white circle No need for the menus at the top of the screen. If you go to Preferences>General and turn on Allow Floating Documents, you can have floating windows by default in all recent versions of PSE except for 9.0.3:
    http://barbarabrundage.com/2011/04/19/photoshop-elements-9-0-3/

  • Coherence 3.6.0 transactional cache and POF - NULL values

    Hi,
    We are trying to use the new transactional scheme defined in 3.6.0 and we encounter an abnormal behaviour. The code executes without any exception or warnings but in the cache we find the key associated with a NULL value.
    To try to identify the problem, we defined two services (see cache-config below):
    - one transactional cache
    - one distributed cache
    If we try to insert into transactional cache primitives or strings everything is normal (both key and value are visible using coherence console). But if we try to insert custom classes using POF, the key is inserted with a NULL value.
    In same cluster we defined a distributed cache that uses the same POF classes/configuration. A call to put will succeed in any scenario (both key and value are visible using coherence console).
    <?xml version="1.0"?>
    <!DOCTYPE cache-config SYSTEM "cache-config.dtd">
    <cache-config>
         <caching-scheme-mapping>
              <cache-mapping>
                   <cache-name>cnt.*</cache-name>
                   <scheme-name>storage.transactionalcache.cnt.scheme</scheme-name>
              </cache-mapping>
              <cache-mapping>
                   <cache-name>stt.*</cache-name>
                   <scheme-name>storage.distributedcache.stt.scheme</scheme-name>
              </cache-mapping>
         </caching-scheme-mapping>
         <caching-schemes>
              <transactional-scheme>
                   <scheme-name>storage.transactionalcache.cnt.scheme</scheme-name>
                   <service-name>storage.transactionalcache.cnt</service-name>
                   <thread-count>10</thread-count>
                   <serializer>
                        <class-name>com.tangosol.io.pof.ConfigurablePofContext</class-name>
                        <init-params>
                             <init-param>
                                  <param-type>String</param-type>
                                  <param-value>cnt-pof-config.xml</param-value>
                             </init-param>
                        </init-params>
                   </serializer>
                   <backing-map-scheme>
                        <local-scheme>
                             <high-units>250M</high-units>
                             <unit-calculator>binary</unit-calculator>
                        </local-scheme>
                   </backing-map-scheme>
                   <autostart>true</autostart>
              </transactional-scheme>
              <distributed-scheme>
                   <scheme-name>storage.distributedcache.stt.scheme</scheme-name>
                   <service-name>storage.distributedcache.stt</service-name>
                   <serializer>
                        <class-name>com.tangosol.io.pof.ConfigurablePofContext</class-name>
                        <init-params>
                             <init-param>
                                  <param-type>String</param-type>
                                  <param-value>cnt-pof-config.xml</param-value>
                             </init-param>
                        </init-params>
                   </serializer>
                   <backing-map-scheme>
                        <local-scheme>
                             <high-units>250M</high-units>
                             <unit-calculator>binary</unit-calculator>
                        </local-scheme>
                   </backing-map-scheme>
                   <autostart>true</autostart>
              </distributed-scheme>
         </caching-schemes>
    </cache-config>
    Failing code (uses transaction APIs 3.6.0):
         public static void main(String[] args)
              Connection con = new DefaultConnectionFactory().createConnection("storage.transactionalcache.cnt");
              con.setAutoCommit(false);
              try
                   OptimisticNamedCache cache = con.getNamedCache("cnt.t1");
                   CId tID = new CId();
                   tID.setId(11111L);
                   C tC = new C();
                   tC.setVal(new BigDecimal("100.1"));
                   cache.insert(tID, tC);
                   con.commit();
              catch (Exception e)
                   e.printStackTrace();
                   con.rollback();
              finally
                   con.close();
    Code that succeeds (but without transaction APIs):
         public static void main(String[] args)
              try
                   NamedCache cache = CacheFactory.getCache("stt.t1");
                   CId tID = new CId();
                   tID.setId(11111L);
                   C tC = new C();
                   tC.setVal(new BigDecimal("100.1"));
                   cache.put(tID, tC);
              catch (Exception e)
                   e.printStackTrace();
              finally
    And here is what we list using coherence console if we use transactional APIs:
    Map (cnt.t1): list
    CId {
    id = 11111
    } = null
    Any suggestion, please?

    Cristian,
    After looking at your configuration I noticed that your configuration is incorrect. For a transactional scheme you cannot specify a backing-map-scheme.
    Your config contained:
    <backing-map-scheme>
    <local-scheme>
    <high-units>250M</high-units>
    <unit-calculator>binary</unit-calculator>
    </local-scheme>
    </backing-map-scheme>To specify high-units for a transactional scheme, simply provide a high-units element directly under the transactional-scheme element.
    <transactional-scheme>
        <scheme-name>small-high-units</scheme-name>
        <service-name>TestTxnService</service-name>
        <autostart>true</autostart>
        <high-units>1M</high-units>
    </transactional-scheme>http://download.oracle.com/docs/cd/E15357_01/coh.360/e15723/api_transactionslocks.htm#BEIBACHA
    The reason that it is not allowable to specify a backing-map-scheme for a transactional scheme is that transactional caches use their own storage.
    I am not sure why this would work with primitives and only fail with POF. We will look into this further here and try to reproduce.
    Can you please change your configuration with the above changes and let us know your results.
    Thanks,
    John
    Edited by: jspeidel on Sep 16, 2010 10:44 AM

Maybe you are looking for

  • Mistake when opening Adobe Muse CC

    At start of Adobe Muse CC there is an error message of the following contents and the application isn't started. As it is possible to solve this problem. Thanks.

  • Winter

    My device manager shows a problem with a device called "winter v1.3" Windows keeps trying to load a driver, but can't find one. Anyone know what "winter v1.3" is? TIA

  • Minimum playback spec for packaged flash game

    I can't seem to find any definitive information on the minimum playback specification of Flash packaged applications. I am developing a series of games for both Mac and PC and would like to include a minimum playback specification. I will be using Fl

  • Performance isues for uploading file

    Hello - Has anyone hit any performance issues when uploading files, using the obj.setSource('HTTP'...) method? Seems like all the examples I've seen have to call the "upload" procedure one time per upload. That is, unless you know haead of time that

  • Reuse of Equipment (Material+Serial) in Intracompany Sale

    Dear Experts I am technical consultant. However I got stuck into one functional scenario. Client has got two companies with company codes 1101 & 900. Both use same SAP system for their processes. They generally do Intracompany Sales. For Ex. Sale fro