Re: hibernate question ?
You probably don't need to initialize 'Address#addressSet' explicitly.
I'm puzzled why people do that in entity classes. What does it provide?
Tom Anderson wrote:
The ability to say new Address().getAddressSet().add(something) without
getting a NullPointerException. Didn't we talk about this before?
That would only be guaranteed if the setter rejects or substitutes 'null'
values, which the OP did not show. In fact, they don't show a setter for that
field at all, so one wonders how any useful information gets into it.
I could understand the initialization if there were an assertable 'field !=
null' invariant, but that is not demonstrated here.
I remain dubious about the value of preventing null in the retrieved value.
None of the other values are thus guarded. With any non-primitive entity
attribute, and that's nearly all entity attributes, you have to check for
possible 'null' values if the corresponding data store might contain NULL. It
doesn't seem like such a stretch to have to check the collection attributes, too.
Either way, if you have or intend to have an invariant like 'addressSet !=
null', then document and enforce it throughout with logic and 'assert'
statements. Otherwise the initialization to non-'null' is just useless fooferol.
I'm more concerned about the setter for the ID field myself.
Well, and the fact that the OP has put the address set in the address
rather than in the student, that the setter for it is called
setAuthDevices, that he calls his Student variable 'emp', and various
other small signs that he has no idea what he's doing.
Yes, I was imputing the likely resolution of those minor issues in my
responses. I should not have done that. No doubt that plethora of
programming peccadilloes produced the proffered problem.