[英]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.)
我并不完全相信我正在使用一组兼容的持久性库(对烹饪手册的详细介绍如何正确地混合和匹配这些库将受到高度赞赏。)
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.