I’ll preface my question by saying that I’m a beginner Java EE developer.
I wrote the following code. Why does this get the ID?
MsItemDTO msItemDTO = new MsItemDTO();
msItemDTO.setItemID(trInboundD.getItemID().getItemID());
trInboundDDTO.setItemID(msItemDTO);
Any why doesn’t get the ID (the ID = null)?
trInboundDDTO.setItemID(new MsItemDTO(trInboundD.getItemID().getItemID()));
We will walk through above code in detail:
MsItemDTOclass and object name ismsItemDTO.msItemDTOthat we have create in first line.msItemDTOto another objecttrInboundDDTOItem Id value.Now we will have a look into the other code:
This line will create an object for MsItemDTO with some
argumentscalledtrInboundD.getItemID().getItemID(). Here you need to write a constructor to create object with this arguments. Otherwise it will not create any object and it saves Item id as null. So object is different here. And second one is that we are trying to set this different object to another objecttrInboundDDTOItem Id which will be conflict.Hope this helps you 🙂