एक अजीब समस्या का सामना कर रहा हूं, मैंने इसे घंटों तक गुगल किया है, लेकिन इसे हल करने का तरीका नहीं पता था।कक्षा में अवैध श्रेणी: अपवाद: ..., संपत्ति का गेटर विधि: आईडी
यहां स्थिति है: मेरे पास दो वर्ग Roles
और Privileges
संबंध कईToMany के साथ है। एक भूमिका में विशेषाधिकार जोड़ने पर, saveOrUpdate(role)
पर कॉलिंग, मैं इस अपवाद में आया था।
यहाँ भूमिका कक्षा
@Entity
@Table(name = "ROLES")
public class Role implements GenericDomain {
private static final long serialVersionUID = -7620550658984151796L;
private Long id;
private String code;
private String name;
private Set<User> users = new HashSet<User>(0);
private Set<Privilege> privileges = new HashSet<Privilege>(0);
public Role() {
}
public Role(String code, String name) {
this.code = code;
this.name = name;
}
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "ID")
public Long getId() { return id; }
public void setId(Long id) { this.id = id; }
@Column(name = "CODE", unique = true, nullable = false, length = 16)
@NotEmpty(message= "password.required")
@Length(min = 3, max = 16)
public String getCode() { return code; }
public void setCode(String code) { this.code = code; }
@Column(name="NAME", nullable = false, length = 64)
@NotEmpty
@Length(min = 1, max = 32)
public String getName() { return name; }
public void setName(String name) { this.name = name; }
@ManyToMany(cascade=CascadeType.ALL)
@JoinTable(name = "ROLES_PRIVILEGES"
, joinColumns = { @JoinColumn(name = "ROLE_ID") }
, inverseJoinColumns = { @JoinColumn(name = "PRIVILEGE_ID") }
)
public Set<Privilege> getPrivileges() {
return this.privileges;
}
public void setPrivileges(Set<Privilege> privileges) {
this.privileges = privileges;
}
/* overide of hascode, equals*/
}
यहाँ है विशेषाधिकार कक्षा
@Entity
@Table(name = "PRIVILEGES")
public class Privilege implements GenericDomain {
private static final long serialVersionUID = 4649689934972816194L;
private Long id;
private String code;
private Set<Role> roles = new HashSet<Role>(0);
public Privilege() {
}
public Privilege(String code) {
this.code = code;
}
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "ID")
public Long getId() { return id; }
public void setId(Long id) { this.id = id; }
@Column(name = "CODE", unique = true, nullable = false, length = 16)
@NotEmpty(message= "password.required")
@Length(min = 3, max = 16)
public String getCode() { return code; }
public void setCode(String code) { this.code = code; }
@ManyToMany(cascade=CascadeType.REFRESH, mappedBy="privileges")
public Set<Role> getRoles() {
return this.roles;
}
public void setRoles(Set<Role> roles) {
this.roles = roles;
}
/*overide equals and hascode*/
}
यहाँ है और अपवाद है:
IllegalArgumentException in class: com.stunaz.domain.Privilege, getter method of property: id
....
javax.persistence.PersistenceException: org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of com.stunaz.domain.Privilege.id
....
java.lang.IllegalArgumentException: object is not an instance of declaring class
इसके somethi लगता है एनजी मेरे मैपिंग के साथ गलत है, कहीं कहीं मुझे ऑब्जेक्ट पास करना चाहिए लेकिन मैं एक आईडी पास कर रहा हूं। लेकिन मुझे वह गलती नहीं दिखाई दे रही है।
किसी भी सलाह के लिए धन्यवाद।
मैंने कोड को परिभाषित किया है जैसा कि आप अपने उदाहरण में कर रहे हैं और यह मेरे लिए ठीक काम करता है। शायद आप अपनी पोस्ट में उल्लेख की गई विधिOrUpdate विधि को दिखा सकते हैं। शायद समस्या वहाँ है। –
हाँ आप हाइबरनेट –
के साथ बिल्कुल सही नहीं हैं क्या आपने इस समस्या को हल किया? मुझे मेरी परियोजना में एक ही त्रुटि है। –