У меня есть класс сущности. Когда я упорствую, я получаю сообщение об ошибке: «не удалось получить значение поля с помощью коэффициента отражения».Hibernate JPA Persist
Пожалуйста, помогите мне.
Мой класс сущностей код:
@Entity
@Table(name = "class")
@NamedQueries({
@NamedQuery(name = "SchoolClass.findAll", query = "SELECT c FROM SchoolClass c"),
@NamedQuery(name = "SchoolClass.findById", query = "SELECT c FROM SchoolClass c WHERE c.id = :id")
})
public class SchoolClass implements Serializable {
/**
* Generated Serial Version ID
*/
private static final long serialVersionUID = 6703663444336018288L;
@Id
@Column(nullable = false, updatable = false)
private Long id;
@Column(nullable = false, length = 100)
private String name;
/**
* @return The getter method of the 'id' instance variable
*/
public Long getId() {
return id;
}
/**
* @param The setter method of the 'id' instance variable
*/
public void setId(final Long id) {
this.id = id;
}
/**
* @return The getter method of the 'name' instance variable
*/
public String getName() {
return name;
}
/**
* @param The setter method of the 'name' instance variable
*/
public void setName(final String name) {
this.name = name;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "SchoolClass [id=" + id + ", name=" + name + "]";
}
}
Моя настойчивость Код:
try {
final UserTransaction transaction = (UserTransaction) new InitialContext()
.lookup("java:comp/UserTransaction");
transaction.begin();
entityManager.persist(schoolClass); // Exception here
entityManager.flush();
transaction.commit();
} catch (SecurityException | IllegalStateException | NamingException | NotSupportedException | SystemException
| RollbackException | HeuristicMixedException | HeuristicRollbackException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Мой исключение:
Вызванный: javax.persistence.PersistenceException: org.hibernate.PropertyAccessException: может не получить значение поля путем отражения getter of com.ilkerkonar.applications.schoolproject.orm.model.SchoolClass.id at org.hibernate.jpa.spi .AbstractEntityManagerImpl.convert (AbstractEntityManagerImpl.java:1763) на org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert (AbstractEntityManagerImpl.java:1677) в org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert (AbstractEntityManagerImpl.java:1683) на org.hibernate.jpa.spi.AbstractEntityManagerImpl.persist (AbstractEntityManagerImpl.java:1187) на com.sun.enterprise.container.common.impl.EntityManagerWrapper.persist (EntityManagerWrapper.java:287) в com.ilkerkonar .applications.schoolproject.orm.service.ClassService.addNewClass (ClassService.java:61)
Да, я попробовал @GeneratedValue, а также удалил updatable = false. Но никто из них не работает. Я получаю ту же ошибку. – Softengilker