Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleDbPersistenceManager.java
===================================================================
--- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleDbPersistenceManager.java	(revision 644105)
+++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleDbPersistenceManager.java	(working copy)
@@ -55,6 +55,7 @@
 import org.apache.jackrabbit.core.persistence.bundle.util.ErrorHandling;
 import org.apache.jackrabbit.core.persistence.bundle.util.NodePropBundle;
 import org.apache.jackrabbit.core.persistence.bundle.util.StringIndex;
+import org.apache.jackrabbit.core.persistence.bundle.util.ItemStateBinding;
 import org.apache.jackrabbit.core.persistence.util.BLOBStore;
 import org.apache.jackrabbit.core.persistence.util.FileSystemBLOBStore;
 import org.apache.jackrabbit.core.persistence.util.Serializer;
@@ -786,11 +787,17 @@
                     try {
                         // parse and check bundle
                         // check bundle will log any problems itself
-                        if (binding.checkBundle(din)) {
+                        int version = binding.checkBundle(din);
+                        if (version >= 0) {
                             // reset stream for readBundle()
                             din = new DataInputStream(blob.getBinaryStream());
                             NodePropBundle bundle = binding.readBundle(din, id);
                             checkBundleConsistency(id, bundle, fix, modifications);
+                            // if version is not latest, add to modificaitons
+                            if (fix && version <= ItemStateBinding.VERSION_CURRENT) {
+                                log.info("Bundle not serialized with latest version, marking for fixing: {}", id);
+                                modifications.add(bundle);
+                            }
                         } else {
                             log.error("invalid bundle '" + id + "', see previous BundleBinding error log entry");
                         }
@@ -1048,8 +1055,7 @@
                 }
                 result.add(current);
             }
-            ListNodeIdIterator it = new ListNodeIdIterator(result);
-            return it;
+            return new ListNodeIdIterator(result);
         } catch (SQLException e) {
             String msg = "getAllNodeIds failed.";
             log.error(msg, e);
@@ -1101,7 +1107,7 @@
             DataInputStream din = new DataInputStream(new ByteArrayInputStream(bytes));
             
             if (checkBeforeLoading) {
-                if (binding.checkBundle(din)) {
+                if (binding.checkBundle(din) < 0) {
                     // reset stream for readBundle()
                     din = new DataInputStream(new ByteArrayInputStream(bytes));
                 } else {
@@ -1540,7 +1546,7 @@
 
     /**
      * Iterator over an in-memory list of node ids.
-     * This helper class is used by {@link BundleDbPersistenceManager#getAllNodeIds()}.
+     * This helper class is used by {@link BundleDbPersistenceManager#getAllNodeIds}.
      */
     private class ListNodeIdIterator implements NodeIdIterator {
 
Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/BundleBinding.java
===================================================================
--- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/BundleBinding.java	(revision 644105)
+++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/BundleBinding.java	(working copy)
@@ -86,7 +86,7 @@
         // get version
         int version = (index >> 24) & 0xff;
         index &= 0x00ffffff;
-        String uri = nsIndex.indexToString(index);
+        String uri = getNamespaceUri(index, version);
         String local = nameIndex.indexToString(in.readInt());
         Name nodeTypeName = NameFactoryImpl.getInstance().create(uri, local);
 
@@ -101,20 +101,20 @@
 
         // mixin types
         Set mixinTypeNames = new HashSet();
-        Name name = readIndexedQName(in);
+        Name name = readIndexedQName(in, version);
         while (name != null) {
             mixinTypeNames.add(name);
-            name = readIndexedQName(in);
+            name = readIndexedQName(in, version);
         }
         bundle.setMixinTypeNames(mixinTypeNames);
 
         // properties
-        name = readIndexedQName(in);
+        name = readIndexedQName(in, version);
         while (name != null) {
             PropertyId pId = new PropertyId(bundle.getId(), name);
-            NodePropBundle.PropertyEntry pState = readPropertyEntry(in, pId);
+            NodePropBundle.PropertyEntry pState = readPropertyEntry(in, pId, version);
             bundle.addProperty(pState);
-            name = readIndexedQName(in);
+            name = readIndexedQName(in, version);
         }
 
         // set referenceable flag
@@ -123,7 +123,7 @@
         // child nodes (list of uuid/name pairs)
         NodeId childId = readID(in);
         while (childId != null) {
-            bundle.addChildNodeEntry(readQName(in), childId);
+            bundle.addChildNodeEntry(readQName(in, version), childId);
             childId = readID(in);
         }
 
@@ -151,10 +151,10 @@
      * Checks a <code>NodePropBundle</code> from a data input stream.
      *
      * @param in the input stream
-     * @return <code>true</code> if the data is valid;
-     *         <code>false</code> otherwise.
+     * @return the serialization version if the data is valid;
+     *         -1 otherwise.
      */
-    public boolean checkBundle(DataInputStream in) {
+    public int checkBundle(DataInputStream in) {
         int version;
         // primaryType & version
         try {
@@ -164,70 +164,70 @@
             // get version
             version = (index >> 24) & 0xff;
             index &= 0x00ffffff;
-            String uri = nsIndex.indexToString(index);
+            String uri = getNamespaceUri(index, version);
             String local = nameIndex.indexToString(in.readInt());
             Name nodeTypeName = NameFactoryImpl.getInstance().create(uri, local);
 
-            log.info("Serialzation Version: " + version);
+            log.info("Serialization Version: " + version);
             log.info("NodeTypeName: " + nodeTypeName);
         } catch (IOException e) {
             log.error("Error while reading NodeTypeName: " + e);
-            return false;
+            return -1;
         }
         try {
             UUID parentUuid = readUUID(in);
             log.info("ParentUUID: " + parentUuid);
         } catch (IOException e) {
             log.error("Error while reading ParentUUID: " + e);
-            return false;
+            return -1;
         }
         try {
             String definitionId = in.readUTF();
             log.info("DefinitionId: " + definitionId);
         } catch (IOException e) {
             log.error("Error while reading DefinitionId: " + e);
-            return false;
+            return -1;
         }
         try {
-            Name mixinName = readIndexedQName(in);
+            Name mixinName = readIndexedQName(in, version);
             while (mixinName != null) {
                 log.info("MixinTypeName: " + mixinName);
-                mixinName = readIndexedQName(in);
+                mixinName = readIndexedQName(in, version);
             }
         } catch (IOException e) {
             log.error("Error while reading MixinTypes: " + e);
-            return false;
+            return -1;
         }
         try {
-            Name propName = readIndexedQName(in);
+            Name propName = readIndexedQName(in, version);
             while (propName != null) {
                 log.info("PropertyName: " + propName);
-                if (!checkPropertyState(in)) {
-                    return false;
+                if (!checkPropertyState(in, version)) {
+                    return -1;
                 }
-                propName = readIndexedQName(in);
+                propName = readIndexedQName(in, version);
             }
         } catch (IOException e) {
             log.error("Error while reading property names: " + e);
-            return false;
+            return -1;
         }
         try {
             boolean hasUUID = in.readBoolean();
             log.info("hasUUID: " + hasUUID);
         } catch (IOException e) {
             log.error("Error while reading 'hasUUID': " + e);
-            return false;
+            return -1;
         }
         try {
             UUID cneUUID = readUUID(in);
             while (cneUUID != null) {
-                Name cneName = readQName(in);
+                Name cneName = readQName(in, version);
                 log.info("ChildNodentry: " + cneUUID + ":" + cneName);
                 cneUUID = readUUID(in);
             }
         } catch (IOException e) {
             log.error("Error while reading child node entry: " + e);
-            return false;
+            return -1;
         }
 
         if (version >= VERSION_1) {
@@ -236,11 +236,24 @@
                 log.info("modCount: " + modCount);
             } catch (IOException e) {
                 log.error("Error while reading mod cout: " + e);
-                return false;
+                return -1;
             }
         }
 
-        return true;
+        // read shared set, since version 2.0
+        if (version >= VERSION_2) {
+            try {
+                // shared set (list of parent uuids)
+                NodeId parentId = readID(in);
+                while (parentId != null) {
+                    parentId = readID(in);
+                }
+            } catch (IOException e) {
+                log.error("Error while reading shared set: " + e);
+                return -1;
+            }
+        }
+        return version;
     }
 
     /**
@@ -255,7 +268,7 @@
         long size = out.size();
 
         // primaryType and version
-        out.writeInt((VERSION_CURRENT << 24) | nsIndex.stringToIndex(bundle.getNodeTypeName().getNamespaceURI()));
+        out.writeInt((VERSION_CURRENT << 24) | nameIndex.stringToIndex(bundle.getNodeTypeName().getNamespaceURI()));
         out.writeInt(nameIndex.stringToIndex(bundle.getNodeTypeName().getLocalName()));
 
         // parentUUID
@@ -316,10 +329,12 @@
      *
      * @param in the input stream
      * @param id the property id for the new propert entry
+     * @param version the serialization version
      * @return the property entry
      * @throws IOException if an I/O error occurs.
      */
-    public NodePropBundle.PropertyEntry readPropertyEntry(DataInputStream in, PropertyId id)
+    public NodePropBundle.PropertyEntry readPropertyEntry(DataInputStream in, 
+                                                          PropertyId id, int version)
             throws IOException {
         NodePropBundle.PropertyEntry entry = new NodePropBundle.PropertyEntry(id);
         // type and modcount
@@ -378,7 +393,7 @@
                     val = InternalValue.create(in.readBoolean());
                     break;
                 case PropertyType.NAME:
-                    val = InternalValue.create(readQName(in));
+                    val = InternalValue.create(readQName(in, version));
                     break;
                 case PropertyType.REFERENCE:
                     val = InternalValue.create(readUUID(in));
@@ -403,10 +418,11 @@
      * Checks a <code>PropertyState</code> from the data input stream.
      *
      * @param in the input stream
+     * @param version the serialization version
      * @return <code>true</code> if the data is valid;
      *         <code>false</code> otherwise.
      */
-    public boolean checkPropertyState(DataInputStream in) {
+    public boolean checkPropertyState(DataInputStream in, int version) {
         int type;
         try {
             type = in.readInt();
@@ -509,7 +525,7 @@
                     break;
                 case PropertyType.NAME:
                     try {
-                        Name name = readQName(in);
+                        Name name = readQName(in, version);
                         log.info("  name: " + name);
                     } catch (IOException e) {
                         log.error("Error while reading name value: " + e);
Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ItemStateBinding.java
===================================================================
--- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ItemStateBinding.java	(revision 644105)
+++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ItemStateBinding.java	(working copy)
@@ -49,14 +49,19 @@
     public static final int VERSION_1 = 1;
 
     /**
-     * serialization version 2
+     * serialization version 2 (adds shared set)
      */
     public static final int VERSION_2 = 2;
 
     /**
+     * serialization version 3 (removes namespace idx)
+     */
+    public static final int VERSION_3 = 3;
+
+    /**
      * current version
      */
-    public static final int VERSION_CURRENT = VERSION_2;
+    public static final int VERSION_CURRENT = VERSION_3;
 
     /**
      * the namespace index
@@ -149,10 +154,10 @@
             throws IOException {
         NodeReferences state = new NodeReferences(id);
         int count = in.readInt();   // count & version
-        // int version = (count >> 24) | 0x0ff;
+        int version = (count >> 24) | 0x0ff;
         count &= 0x00ffffff;
         for (int i = 0; i < count; i++) {
-            state.addReference(readPropertyId(in));    // propertyId
+            state.addReference(readPropertyId(in, version));    // propertyId
         }
         return state;
     }
@@ -204,7 +209,7 @@
         int count = in.readInt();   // count
         Set set = new HashSet(count);
         for (int i = 0; i < count; i++) {
-            set.add(readQName(in)); // name
+            set.add(readQName(in, version)); // name
         }
         if (set.size() > 0) {
             state.setMixinTypeNames(set);
@@ -212,12 +217,12 @@
         // properties (names)
         count = in.readInt();   // count
         for (int i = 0; i < count; i++) {
-            state.addPropertyName(readIndexedQName(in)); // name
+            state.addPropertyName(readIndexedQName(in, version)); // name
         }
         // child nodes (list of name/uuid pairs)
         count = in.readInt();   // count
         for (int i = 0; i < count; i++) {
-            Name name = readQName(in);
+            Name name = readQName(in, version);
             NodeId parentId = readID(in);
             state.addChildNodeEntry(name, parentId);
         }
@@ -365,11 +370,12 @@
     /**
      * Deserializes a Name
      * @param in the input stream
+     * @param version the serialization version
      * @return the qname
      * @throws IOException in an I/O error occurs.
      */
-    public Name readQName(DataInputStream in) throws IOException {
-        String uri = nsIndex.indexToString(in.readInt());
+    public Name readQName(DataInputStream in, int version) throws IOException {
+        String uri = getNamespaceUri(in.readInt(), version);
         String local = in.readUTF();
         return NameFactoryImpl.getInstance().create(uri, local);
     }
@@ -408,15 +414,16 @@
     /**
      * Deserializes an indexed Name
      * @param in the input stream
+     * @param version the serialization version
      * @return the qname
      * @throws IOException in an I/O error occurs.
      */
-    public Name readIndexedQName(DataInputStream in) throws IOException {
+    public Name readIndexedQName(DataInputStream in, int version) throws IOException {
         int index = in.readInt();
         if (index < 0) {
             return null;
         } else {
-            String uri = nsIndex.indexToString(index);
+            String uri = getNamespaceUri(index, version);
             String local = nameIndex.indexToString(in.readInt());
             return NameFactoryImpl.getInstance().create(uri, local);
         }
@@ -432,7 +439,7 @@
         if (name == null) {
             out.writeInt(-1);
         } else {
-            out.writeInt(nsIndex.stringToIndex(name.getNamespaceURI()));
+            out.writeInt(nameIndex.stringToIndex(name.getNamespaceURI()));
             out.writeInt(nameIndex.stringToIndex(name.getLocalName()));
         }
     }
@@ -451,12 +458,33 @@
     /**
      * Deserializes a PropertyId
      * @param in the input stream
+     * @param version the serialization version
      * @return the property id
      * @throws IOException in an I/O error occurs.
      */
-    public PropertyId readPropertyId(DataInputStream in) throws IOException {
+    public PropertyId readPropertyId(DataInputStream in, int version)
+            throws IOException {
         UUID uuid = readUUID(in);
-        Name name = readQName(in);
+        Name name = readQName(in, version);
         return new PropertyId(new NodeId(uuid), name);
     }
+
+    /**
+     * Helper method for retrieving the namespace uri either from the
+     * {@link #nsIndex} if version == 2, or from the {@link #nameIndex} if
+     * version >= 3.
+     *
+     * @param idx the index of the uri
+     * @param version the serializarion version
+     * @return the uri
+     */
+    protected String getNamespaceUri(int idx, int version) {
+        if (version >= VERSION_3) {
+            return nameIndex.indexToString(idx);
+        } else {
+            return nsIndex.indexToString(idx);
+        }
+    }
+
+
 }
