简体   繁体   English

Hibernate / JPA:无法通过反射设置器设置字段值

[英]Hibernate/JPA: could not set a field value by reflection setter

My JPA/Hibernate odyssey continues... 我的JPA / Hibernate奥德赛继续......

I am trying to work around this issue , and so I have had to define primitive @Ids in my class that uses 3 entity fields as a composite key. 我正在努力解决这个问题 ,所以我不得不在我的类中定义原始的@Ids,它使用3个实体字段作为复合键。 This seems to get me a bit further, but now I'm getting this when persisting: 这似乎让我更进一步,但现在我坚持下去:

javax.persistence.PersistenceException: org.hibernate.PropertyAccessException: could not set a field value by reflection setter of com.example.model.LanguageSkill.stafferId

Here's my composite class: 这是我的复合类:

public class LanguageSkill implements Serializable
{
    @Id
    @GeneratedValue (strategy = GenerationType.IDENTITY)
    @Column(name = "Staffer_ID")
    private Long stafferId;

    @Id
    @ManyToOne(cascade = CascadeType.ALL)
    @MapsId(value = "stafferId")
    private Staffer staffer;

    @Id
    @GeneratedValue (strategy = GenerationType.IDENTITY)
    @Column(name = "Language_ID")
    private Long languageId;

    @ManyToOne
    @MapsId(value= "languageId")
    private Language language;

    @Id
    @GeneratedValue (strategy = GenerationType.IDENTITY)
    @Column(name = "Language_Proficiency_ID")
    private Long languageProficiencyId;

    @ManyToOne
    @MapsId(value= "languageProficiencyId")
    private LanguageProficiency languageProficiency;
}

I do have proper getters and setters (IDE-generated) for both the primitives as well as the entities. 我确实为基元和实体都有适当的getter和setter(IDE生成)。

Here are my libs. 这是我的库。 I'm not totally convinced that I'm using a compatible set of persistence libraries (references to a cookbook detailing how to properly mix-and-match these would be highly appreciated.) 我并不完全相信我正在使用一组兼容的持久性库(对烹饪手册的详细介绍如何正确地混合和匹配这些库将受到高度赞赏。)

  • Hibernate 3.5.6-SNAPSHOT Hibernate 3.5.6-SNAPSHOT
  • hibernate-jpamodelgen 1.1.0.CR1 hibernate-jpamodelgen 1.1.0.CR1
  • hibernate-validator 3.1.0.GA hibernate-validator 3.1.0.GA
  • MySQL 5.1.6 MySQL 5.1.6
  • jsr250-api 1.0 jsr250-api 1.0
  • javax.validation validation-api 1.0.0.GA javax.validation validation-api 1.0.0.GA

Wow, it's frustrating. 哇,这很令人沮丧。 3 days now full time trying to solve various issues like this just for basic ORM. 3天现在全职尝试解决这样的各种问题只是为了基本的ORM。 I feel defective. 我觉得有缺陷。 :-( :-(

It seems a correct code. 这似乎是一个正确的代码。 I had problem with this exception when I used Blob[] 当我使用Blob []时,我遇到了这个异常的问题

@Lob
@Column(name="DOCUMENTO",nullable=false)
private Blob[] documento;

But changing by Byte[], I solved this problem. 但是通过Byte []改变,我解决了这个问题。

I have only a occurrence, looking Oracle data types, I have seen this LONG is Character data of variable length (A bigger version the VARCHAR2 datatype). 我只看到了Oracle数据类型,我看到这个LONG是可变长度的字符数据(VARCHAR2数据类型的更大版本)。

I assume that your ID is a Integer....Why not change Long by Integer? 我假设你的ID是一个整数....为什么不用Integer改变Long? You must remember that it only accepts primitive types. 你必须记住它只接受原始类型。

This is my code and it works fine: 这是我的代码,它工作正常:

@Id
@SequenceGenerator(sequenceName="SQ_DOCUMENTO",name="seqDocumento")
@GeneratedValue(strategy=GenerationType.SEQUENCE,generator="seqDocumento")
private Integer idDocumento;

I use Hibernate 3.5.6-final, Spring 3.0.4, Junit 4 and Oracle 11g. 我使用Hibernate 3.5.6-final,Spring 3.0.4,Junit 4和Oracle 11g。

您必须删除@GeneratedValue注释。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用ManyToOne获取org.hibernate.PropertyAccessException的JPA Composite键:无法通过反射设置器设置字段值 - JPA Composite key with ManyToOne getting org.hibernate.PropertyAccessException: could not set a field value by reflection setter of 无法通过反射设置器设置字段值<class> - could not set a field value by reflection setter of <class> 无法通过反射设置器设置字段值 - could not set a field value by reflection setter 在连接表和hibernate.PropertyAccessException中映射值:无法通过反射设置器设置字段值 - Mapping Value in Junction Table & hibernate.PropertyAccessException: could not set a field value by reflection setter 如何修复org.hibernate.PropertyAccessException:无法通过反射设置器设置字段值 - How to fix org.hibernate.PropertyAccessException: Could not set field value value by reflection setter of Hibernate:无法通过com.mahlzeit.datamodel.address.City.id的反射设置器设置字段值 - Hibernate: could not set a field value by reflection setter of com.mahlzeit.datamodel.address.City.id JPA-Hibernate-“无法通过继承的反射获取器获取字段值 - JPA-Hibernate - “could not get a field value by reflection getter of with inheritance 无法通过反射设置字段值 - Could not set field value by reflection 无法通过反射休眠获取字段值 - could not get a field value by reflection hibernate Hibernate &amp; Spring - org.hibernate.PropertyAccessException: 无法通过反射设置字段值 [1] 值 - Hibernate & Spring - org.hibernate.PropertyAccessException: Could not set field value [1] value by reflection
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM