2014-12-12 3 views
1

я не могу решить эти новые исключенияЧто вызывает "java.lang.IllegalArgumentException: Не удается установить поле java.lang.Integer"

Can not set java.lang.Integer field GcmRegistraionIdentity.gcmId to GcmRegistraionIdentity 

org.hibernate.PropertyAccessException: could not get a field value by reflection getter of GcmRegistraionIdentity.gcmId 

My Dynamic Web Project (Jee7), ориентированные на

GlassFish Server Open Source Edition 4.1 (build 13) 

Hibernate

Hibernate Core {4.3.7.Final} 

Мои persistence.xml

<persistence version="2.1" 
    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://www.oracle.com/webfolder/technetwork/jsc/xml/ns/persistence/persistence_2_1.xsd"> 
    <persistence-unit name="testPU" transaction-type="JTA"> 
     <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider> 
     <jta-data-source>jdbc/testDB</jta-data-source> 
     <properties> 
      <property name="hibernate.transaction.jta.platform" 
       value="org.hibernate.service.jta.platform.internal.SunOneJtaPlatform" /> 
      <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" /> 
      <property name="hibernate.show_sql" value="true" /> 
     </properties> 
    </persistence-unit> 
</persistence> 

Heres мои EDITED объект класса (частично: например, Геттеры/сеттеры НЕ УКАЗАНЫ)

@Entity 
@Table(name = "gcm_registration") 
public class GcmRegistraionIdentity { 

    @Id 
    @GeneratedValue(strategy = GenerationType.IDENTITY) 
    @Column(name = "gcm_id", unique = true, nullable = false, insertable = false, updatable = false) 
    private Integer gcmId; 

    @Column(name = "registration_id") 
    private String registraionId = null; 

    @Column(name = "created") 
    @Temporal(TemporalType.TIMESTAMP) 
    private Date created; 

    public Integer getGcmId() { 
     return gcmId; 
    } 

    public void setGcmId(final Integer gcmId) { 
     this.gcmId = gcmId; 
    } 

Mysql версия

Version 5.6.22 MySQL Community Server (GPL) 

Я бегу на Mac OS X 10.10.1 (14B25) (Yosemite)

Heres мои JAX-RS класса

@Path("registrations") 
@Stateless 
public class RegistrationResource { 

    @PersistenceContext 
    private EntityManager mEntityManager; 

    @POST 
    @Path("gcm") 
    public void register(final RegistrationIdJson registrationId) { 

     final GcmRegistraionIdentity gcmRegistraionIdentity = new GcmRegistraionIdentity(); 
     gcmRegistraionIdentity.setRegistraionId(registrationId.getRegistrationId()); 

     mEntityManager.persist(gcmRegistraionIdentity); 

    } 

} 

Херес DDL для моей MySql таблицы

CREATE TABLE `gcm_registration` (
    `gcm_id` int(11) NOT NULL AUTO_INCREMENT, 
    `registration_id` varchar(1024) NOT NULL, 
    `created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, 
    PRIMARY KEY (`gcm_id`) 
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; 

ответ

0

Решение было заменить

Hibernate Core {4.3.7.Final} 

с не требовалось

Hibernate Core {4.3.5.Final} 

Никакие другие изменения кода или конфигурации

0

Я буду рекомендовать изменение имени поля идентификатора. Измените таблицу и обновите столбец до «id». Я думаю, что «_id» делает смешные вещи в спящем режиме.

+0

Мой класс GcmRegistration имеет методы получения и установки, я как раз не беспокоить тратить пространство и время, вставляющее их в мой вопрос, поэтому мое утверждение «Heres my entity class (partial)» – Hector

+0

Хорошо, тогда я редактирую свой ответ –

+0

, что передумал, но нет, см. мои правки – Hector