Entity Form Anonymous Users
You should rather use the following code, but there is a problem I will describe.

if (empty($user-&gt;uid))  {
  $entityform-&gt;uid = db_next_id(db_query('SELECT MAX(uid) FROM {users}')-&gt;fetchField());
}


The problem with that code is that it will use the user ID of the next user account that is being created, which could not be the user who created the entity. This is true when:


The anonymous user creates an entity instance
After the code I shown is executed, a new user creates an account
The anonymous user who created the entity instance creates an account


I would rather do the following:


When an anonymous user creates an entity instance, asks for an email address
Save the email address as part of the entity


When a user account is created, and the user logs in the very first time:


Search for any entity instance where the email address is equal to the email address used for the user account
Change the user ID with the user ID associated to that email address


Instead of the email address, you could ask anything else, as long as it is clear to the user that the entered value is requested when s/he creates an account to assign to her/his account any entity s/he creates. As the email address is required to create a user account, I would ask the email address to the anonymous users who creates entities.