什么原因导致“java.lang.IllegalArgumentException:无法设置java.lang.Integer字段” [英] What causes "java.lang.IllegalArgumentException: Can not set java.lang.Integer field"
本文介绍了什么原因导致“java.lang.IllegalArgumentException:无法设置java.lang.Integer字段”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法解决这些 new 异常
无法设置java.lang.Integer字段GcmRegistraionIdentity .gcmId到GcmRegistraionIdentity
org.hibernate.PropertyAccessException:无法通过反射获取字段值getcm of GcmRegistraionIdentity.gcmId
我的动态Web项目(Jee7)定位于
GlassFish Server开源版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 / persistencexmlns: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 =testPUtransaction-type =JTA>
< provider> org.hibernate.jpa.HibernatePersistenceProvider< / provider>
< jta-data-source> jdbc / testDB< / jta-data-source>
<属性>
< property name =hibernate.transaction.jta.platform
value =org.hibernate.service.jta.platform.internal.SunOneJtaPlatform/>
< property name =hibernate.dialectvalue =org.hibernate.dialect.MySQL5InnoDBDialect/>
< property name =hibernate.show_sqlvalue =true/>
< / properties>
< / persistence-unit>
< /余辉>
继承我的 EDITED 实体类(部分:例如Getters / Setters 不显示)
@Entity
@Table(name =gcm_registration)
public class GcmRegistraionIdentity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name =gcm_id,unique = true,nullable = false,可插入= false,updatable = false)
private Integer gcmId;
@Column(name =registration_id)
private String registraionId = null;
@Column(name =created)
@Temporal(TemporalType.TIMESTAMP)
private创建日期;
public Integer getGcmId(){
return gcmId;
}
public void setGcmId(final Integer gcmId){
this.gcmId = gcmId;
}
Mysql版本是
< pre $ 版本5.6.22 MySQL社区服务器(GPL)
我正在运行 Mac OS X 10.10.1(14B25)(Yosemite)
继承我的JAX-RS类
@Path(registrations)
@Stateless
public class RegistrationResource {
@PersistenceContext
私人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;
解决方案
解决方案是取代
Hibernate Core {4.3.7.Final}
与
Hibernate Core {4.3.5.Final}
不需要其他代码或配置更改
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;
解决方案
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
这篇关于什么原因导致“java.lang.IllegalArgumentException:无法设置java.lang.Integer字段”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文