java - if (specialmarkId != null) {.....} got ignored -
i using auto generated jpacontroller
of netbeans 8 using java 1.8.
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); } ..... }
during physical object creation, specialmark
(part of physical object) optional.
it can have value or null.
specialmark
in table physical allows have null values.
when specialmark
null, if (specialmarkid != null) {...}
should skipped. instead, got ignored , proceed.
the error message is
"... instance of null pk has been incorrectly provided find operation. @ db.jpa.physicaljpacontroller.create(physicaljpacontroller.java:57)" system.out.println(specialmarkid+ "...nullvalue"); output "null...nullvalue" shows specialmarkid value null system.out.println(specialmarkid+ "...ain't right");
output "null...ain't right"
shows if (specialmarkid != null) {...}
has been ignored specialmarkid
null.
why (specialmarkid != null) {...}
not work?
i guess specialmarkid
not null, specialmarkid.tostring()
overwriten return string "null"
.
instead of
system.out.println(specialmarkid+ "...nullvalue");
try like
system.out.println((specialmarkid != null? specialmarkid.tostring() + "(not null)": "(this null)") + "...nullvalue");
Comments
Post a Comment