엔티티 클래스가 있습니다. 내가 지속될 때, 나는 오류를 얻는다 : "반사감을 얻음으로써 현장 가치를 얻을 수 없다".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 : 수 com.ilkerkonar.applications.schoolproject.orm.model.SchoolClass.id 에서 org.hibernate.jpa.spi의 반영 getter에 의해 필드 값을 얻지 못한다. org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert에서 org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert (AbstractEntityManagerImpl.java:1677) 에서 .AbstractEntityManagerImpl.convert (AbstractEntityManagerImpl.java:1763) (AbstractEntityManagerImpl.java:1683) at org.hibernate.jpa.spi.AbstractEntityManagerImpl.persist (AbstractEntityManagerImpl.java:1187) at com.sun.enterprise.container.common.impl.EntityManagerWrapper.persist (EntityManagerWrapper.java:287) at com.ilkerkonar .applications.schoolproject.orm.service.ClassService.addNewClass (ClassService.java:61)
예 @GeneratedValue를 시도했지만 updatable = false도 제거했습니다. 그러나 그들 중 누구도 일하지 않습니다. 같은 오류가 발생합니다. – Softengilker