Entity Metadata Wrapper Save VS Node Save when invoked from hook_node_insert Can somebody shine a light into the difference of the two, in terms of their interaction with database when hook_node_insert() is invoked? The documentation explains that 


  Note that when this hook is invoked, the changes have not yet been written to the database, because a database transaction is still in progress. The transaction is not finalized until the save operation is entirely completed and node_save() goes out of scope.


In fact, when I tried doing node_save($node), it will give me an error.

However, if I was doing it this way,

$nodeWrapper = entity_metadata_wrapper('node', node_load($node-&gt;nid));
$nodeWrapper-&gt;title-&gt;set(t("Saved by Entity Save"));
$nodeWrapper-&gt;save();


It works just fine. Has the new node being committed into the database after the $nodeWrapper-&gt;save() was executed?
Essentially, there really isn't much difference between node_save() and the save() method of the entity metadata wrapper. Neither should however be used to save the node passed in as the argument to hook_node_insert().

The argument is passed by reference (since it's an object and all objects are passed by reference in later PHP versions), and any changes you make to it will be included when the node is saved by Drupal just after it's done calling the hook implementation.

Trying to manually save the same node again could trigger endless recursion into your hook_node_insert() implementation.

Just alter the node object as you see fit (setting the title in this case, though that is not a translatable string, so replace t() with check_plain()) and do nothing more.

If you need to do more complex alterations, the entity metadata wrapper could come in handy, but you must remember that any alterations you want to have saved must be performed on the node instance passed as a reference to hook_node_insert(). This means you can't node_load($node-&gt;nid) here first, since that would actually just create a new node object with data that's already in the database. If you do manage to save that node copy without ending up in a recursion loop, it would either mean that the node save already in progress - the reason hook_node_insert() was originally called - overwrites any changes you made, or fails because the new node to be saved already exists.

Instead, pass the $node argument to entity_metadata_wrapper() directly and the wrapper will be able to alter the correct node object for you, but remember to not call save() on the wrapper!