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.)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With