Java 1.8을 사용하여 Netbeans 8의 JPAController
자동 생성을 사용하고 있습니다. 물리적 개체 생성, Specialmark
(대상물의 일부) 동안if (specialmarkId! = null) {.....} 무시되었습니다
public void create(Physical physical) {
if (physical.getTalentCollection() == null) {
physical.setTalentCollection(new ArrayList<Talent>());
}
EntityManager em = null;
try {
em = getEntityManager();
em.getTransaction().begin();
Specialmark specialmarkId = physical.getSpecialmarkId();
System.out.println(specialmarkId+ "...nullValue");
if (specialmarkId != null) {
System.out.println(specialmarkId+ "...ain't right");
specialmarkId = em.getReference(specialmarkId.getClass(), specialmarkId.getId());
physical.setSpecialmarkId(specialmarkId);
}
.....
}
는 선택적이다.
값이 있거나 null 일 수 있습니다.
Specialmark
실제 테이블에서는 null 값을 가질 수 있습니다.
Specialmark
이 null 인 경우 if (specialmarkId != null) {...}
은 건너 뜁니다. 대신, 그것은 무시하고 진행합니다.
오류 메시지도 specialmarkId
가 null "null...ain't right"
쇼 if (specialmarkId != null) {...}
무시되었습니다
"... An instance of a null PK has been incorrectly provided for this find operation.
at db.jpa.PhysicalJpaController.create(PhysicalJpaController.java:57)"
System.out.println(specialmarkId+ "...nullValue");
output "null...nullValue" it shows specialmarkId value is null
System.out.println(specialmarkId+ "...ain't right");
출력이다.
(specialmarkId != null) {...}
이 작동하지 않는 이유는 무엇입니까?
같은
시도 뭔가의
중단 점을 추가하고 변수를 검사하는 방법을 알고 계십니까? 그렇지 않다면 디버깅하는 법을 배워야합니다. 왜냐하면 당신이 그것을 필요로하기 때문입니다. –