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;

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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)"
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=
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)
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.