我无法解决这些新例外
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 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>
继承我的 EDITED 实体类(部分:例如Getters / Setters 未显示)
@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)
继承我的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);
}
}
继承我的MySql表的DDL
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 :(得分:0)
我建议更改id字段的名称。 更改表格并将列更新为&#34; id&#34;。我认为&#34; _id&#34;在休眠时做的很有趣。
答案 1 :(得分:0)
解决方案是替换
Hibernate Core {4.3.7.Final}
与
Hibernate Core {4.3.5.Final}
无需更改其他代码或配置