Upgrade to Hibernate 4.x default_entity_mode=dynamic-map exception
<p>I'm trying to upgrade hibernate from 3.6.10 to 4.3.11, but I'm facing multiple problems. First of all, in hibernate 3.x there was EntityMode session, something of that:</p>

<pre><code>Session session = sessionFactory.openSession().getSession(EntityMode.MAP);
</code></pre>

<p>but support for entity-mode session was removed in hibernate-4.x (see <a href="https://stackoverflow.com/questions/19109319/entitymode-map-with-hibernate-4-2-6-spring-3-2">EntityMode.Map with Hibernate 4.2.6+ Spring 3.2</a>). In 4.x the solution is to have custom SessionFactory configured with <strong>hibernate.default_entity_mode=<em>dynamic-map</em></strong>, but is not working in my case - I get an exception:</p>

<pre><code>org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of test.moro.User.name
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:192)
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.getForInsert(BasicPropertyAccessor.java:204)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.getPropertyValuesToInsert(AbstractEntityTuplizer.java:624)
at org.hibernate.tuple.entity.PojoEntityTuplizer.getPropertyValuesToInsert(PojoEntityTuplizer.java:382)
at org.hibernate.persister.entity.AbstractEntityPersister.getPropertyValuesToInsert(AbstractEntityPersister.java:4817)
at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:268)
at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:195)
at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:126)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:209)
at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:55)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:194)
at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:49)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:715)
at org.hibernate.internal.SessionImpl.save(SessionImpl.java:707)
at test.moro.HibernateDynamicMapTest.test_1(HibernateDynamicMapTest.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:78)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:212)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
</code></pre>

<p>I configured a sample project trying to figuring out where is the problem. 
My hibernate configuration (test.hibernate.cfg.xml):</p>

<pre><code>&lt;hibernate-configuration&gt;
    &lt;session-factory&gt;
        &lt;property name="hibernate.connection.driver_class"&gt;org.h2.Driver&lt;/property&gt;
        &lt;property name="hibernate.connection.password"&gt;sa&lt;/property&gt;
        &lt;property name="hibernate.connection.url"&gt;jdbc:h2:./target/test&lt;/property&gt;
        &lt;property name="hibernate.connection.username"&gt;sa&lt;/property&gt;
        &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.H2Dialect&lt;/property&gt;
        &lt;property name="hibernate.hbm2ddl.auto"&gt;update&lt;/property&gt;
        &lt;property name="hibernate.default_entity_mode"&gt;dynamic-map&lt;/property&gt;
        &lt;!-- Echo all executed SQL to stdout --&gt;
        &lt;property name="show_sql"&gt;true&lt;/property&gt;

        &lt;mapping resource="mapping/User.hbm.xml" /&gt;
    &lt;/session-factory&gt;
&lt;/hibernate-configuration&gt;
</code></pre>

<p>The mapping User.hbm.xml file:</p>

<pre><code>&lt;hibernate-mapping&gt;
    &lt;class entity-name="user" name="test.moro.User" table="USER"&gt;
        &lt;id name="id" type="long"&gt;
            &lt;column name="ID" /&gt;
            &lt;generator class="identity" /&gt;
        &lt;/id&gt;
        &lt;property name="name" type="java.lang.String"&gt;
            &lt;column name="NAME" /&gt;
        &lt;/property&gt;
        &lt;property name="password" type="java.lang.String"&gt;
            &lt;column name="PASSWORD" /&gt;
        &lt;/property&gt;
    &lt;/class&gt;
&lt;/hibernate-mapping&gt;
</code></pre>

<p>The entity:</p>

<pre><code>public class User  implements Serializable {
    private long id;
    private String name;
    private String password;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}
</code></pre>

<p>And the test class wich run the code:</p>

<pre><code>public class HibernateDynamicMapTest {

    @Test
    public void test_1() {
        Configuration configuration = new Configuration();
        configuration.configure("/test.hibernate.cfg.xml");
        StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties());
        SessionFactory sessionFactory = configuration.buildSessionFactory(builder.build());
        //------------------------------

        Session session = sessionFactory.openSession();
        session.beginTransaction();
        Map insertMap = new HashMap();
        insertMap.put("name", "User_1");
        insertMap.put("password", "mypassword");
        session.save("user", insertMap);
        session.getTransaction().commit();
        session.close();
        sessionFactory.close();
    }
}
</code></pre>

<p>Please, help me to fix that error.</p>

<p>P.S.
I observed that if i remove <strong>name="test.moro.User"</strong> from class mapping</p>

<pre><code>&lt;class entity-name="user" name="test.moro.User" table="USER"&gt;...&lt;/class&gt;
</code></pre>

<p>it's working, but I need to preserve the name of class, because is used for mapping hbm to java entities.</p>