My JPA/Hibernate odyssey continues...
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. 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.
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-jpamodelgen 1.1.0.CR1
- hibernate-validator 3.1.0.GA
- MySQL 5.1.6
- jsr250-api 1.0
- 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. I feel defective. :-(
It seems a correct code. I had problem with this exception when I used Blob[]
@Lob
@Column(name="DOCUMENTO",nullable=false)
private Blob[] documento;
But changing by Byte[], I solved this problem.
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).
I assume that your ID is a Integer....Why not change Long by Integer? 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.
You have to remove the @GeneratedValue
annotations.
精彩评论