title: Hibernate 4.3.6 and Glassfish 4.0 JPA 2.1 object is not an instance of declaring class
body: <p>I'm using Hibernate 4.3.6 and Glassfish 4.0 for my ejb project.</p>
  
  <p>My test Dao class :</p>
  
  <pre><code>@PersistenceContext
  private EntityManager entityManager;
  
  public void saveTest(){
      Foo testFoo = new Foo();
      testFoo.setSomething("test");
      entityManager.persist(testFoo);
      entityManager.flush();
  }
  </code></pre>
  
  <p>and  POJO class Foo.class:</p>
  
  <pre><code>@Entity
  @Table(name = "FOO")
  public class Foo implements Serializable {
  
      private static final long serialVersionUID = 1L;
  
      private Long id;
  
      private String something;
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      @Column(name = "T_ID", unique = true, nullable = false, precision = 15, scale = 0)
      public Long getId() {
          return id;
      }
  
      public void setId(Long id) {
          this.id = id;
      }
  
      @Column(name = "T_SOMETHING", length = 50)
      public String getSomething() {
          return something;
      }
  
      public void setSomething(String something) {
          this.adi = something;
      }
  }
  </code></pre>
  
  <p>persistence.xml :</p>
  
  <pre><code> &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
      http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
      version="2.1"&gt;
      &lt;persistence-unit name="TestAppUnit" transaction-type="JTA"&gt;
          &lt;provider&gt;org.hibernate.jpa.HibernatePersistenceProvider&lt;/provider&gt;
  
          &lt;jta-data-source&gt;jdbc/TestApp&lt;/jta-data-source&gt;
  
          &lt;class&gt;com.example.test.Foo&lt;/class&gt;
          &lt;exclude-unlisted-classes&gt;false&lt;/exclude-unlisted-classes&gt;
          &lt;properties&gt;
              &lt;property name="hibernate.transaction.jta.platform"
                  value="org.hibernate.service.jta.platform.internal.SunOneJtaPlatform" /&gt;
              &lt;property name="hibernate.dialect" value="org.hibernate.dialect.Oracle9iDialect" /&gt;
              &lt;property name="hibernate.show_sql" value="true" /&gt;
              &lt;property name="hibernate.format_sql" value="true" /&gt;
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>I can list table data, get data with query and i can remove data from table. But i can't persist or merge.</p>
  
  <p>Exception is:</p>
  
  <pre><code> IllegalArgumentException occurred calling getter of com.example.test.Foo.id
  at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:192)
      at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:346)
      at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:4746)
      at org.hibernate.persister.entity.AbstractEntityPersister.isTransient(AbstractEntityPersister.java:4465)
      at org.hibernate.engine.internal.ForeignKeys.isTransient(ForeignKeys.java:243)
      at org.hibernate.event.internal.AbstractSaveEventListener.getEntityState(AbstractSaveEventListener.java:511)
      at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:100)
      at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
      at org.hibernate.internal.SessionImpl.fireSaveOrUpdate(SessionImpl.java:684)
      at org.hibernate.internal.SessionImpl.saveOrUpdate(SessionImpl.java:676)
      at org.hibernate.internal.SessionImpl.saveOrUpdate(SessionImpl.java:671)
  ....
  
  Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:601)
      at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:169)
  </code></pre>
  
  <p>Where am I doing wrong?</p>
  
  <p>This project working on Glassfish 3.1 with persistence.xml version 1.0(jpa) and without this line :</p>
  
  <pre><code>&lt;property name="hibernate.transaction.jta.platform"
                      value="org.hibernate.service.jta.platform.internal.SunOneJtaPlatform" /&gt;
  </code></pre>
  
  <p><b>Thanks in advance</b></p>