我有两个类:AbstractMailingDirections
和DirectionLoad
。两者都有一个复制构造函数,如下所示:
public AbstractMailingDirections(AbstractMailingDirections toCopy) {
this.message = toCopy.message;
this.defaultDirection = new DirectionLoad(toCopy.defaultDirection);
for (final DirectionLoad dls : toCopy.directionLoads) {
this.directionLoads.add(new DirectionLoad(dls));
}
}
和
public DirectionLoad(DirectionLoad toCopy) {
this.direction = toCopy.direction;
this.transportationContract = toCopy.transportationContract;
this.pickUpTime = toCopy.pickUpTime;
this.acceptanceTime = toCopy.acceptanceTime;
this.acceptanceLocation = toCopy.acceptanceLocation;
this.information = toCopy.information;
}
现在,当我调用
MailingDirections
复制构造函数(只是super(toCopy)
)时,有时我无法复制defaultDirection
的字段。还是不是全部。使用Eclipse调试器甚至更陌生:在这里,我单击了要复制的
AbstractMailingDirections
。在defaultDirection.acceptanceTime
打印中查看toString
如何为17:00,但在字段列表中显示null
。如果单击defaultDirection,则toString
打印将acceptanceTime
字段显示为null
。这让我发疯。任何想法可能是什么原因造成的?
最佳答案
这些是Hibernate实体(或JPA或类似的实体)吗?在那种情况下,访问字段可能会阻止延迟加载魔术,而通过 setter/getter 访问它可能会解决它。