1

I cannot resolve these new exceptions

 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) targeted to

GlassFish Server Open Source Edition  4.1  (build 13)

Hibernate

Hibernate Core {4.3.7.Final}

My 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 my EDITED entity class (partial: e.g Getters/Setters NOT SHOWN)

@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 is

Version 5.6.22 MySQL Community Server (GPL)

I am running on Mac OS X 10.10.1 (14B25) (Yosemite)

Heres my JAX-RS class

@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);

    }

}

Heres the DDL for my MySql table

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;
doplumi
  • 2,938
  • 4
  • 29
  • 45
Hector
  • 4,016
  • 21
  • 112
  • 211

2 Answers2

0

I'll recommend a change in the name of id field. Alter the table and update the column to "id". I think that "_id" is doing funny stuff on hibernate.

Sezin Karli
  • 2,517
  • 19
  • 24
  • My GcmRegistration class has getters and setters, i just didnt bother wasting space and time pasting them into my question, hence my statement "Heres my entity class (partial)" – Hector Dec 12 '14 at 22:05
  • hmm. should not we leave id generation to the db as we annotatded it with GeneratedValue. Can you try persisting without setting the primary key= – Sezin Karli Dec 12 '14 at 22:30
  • I am not setting the primary key. thats why I have specified @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "gcm_id", unique = true, nullable = false, insertable = false, updatable = false) – Hector Dec 12 '14 at 22:34
0

The solution was to replace

Hibernate Core {4.3.7.Final}

with

Hibernate Core {4.3.5.Final}

No other code or configuration changes were required

Hector
  • 4,016
  • 21
  • 112
  • 211