java.lang.IllegalStateException,“Parent 类型的对象的主键为 null”除了我可以打印它并且它不为空
我无法想象还有更多的方法来解决我的问题。这是我昨天制作的一个线程,详细描述了父类和子类: https://stackoverflow.com/questions/3800450/many-to-one-uni Direction-gae-jdo-relationship-amongst-entities
我正在尝试添加一辆卡车并保留它,但是持久性经理坚持认为父项的主键为 NULL,即使我在持久化子项之前记录该值,并且父项不为空,实际上它也是有效的键,也应该设置。为什么持久性管理器看到了我看不到的东西?
try{
if (!findTruck(truck)){
_logger.warning("get tweeter key " + truck.getTweeter().getEncodedKey());
pm.makePersistent(truck);
}
}
finally {
pm.close();
}
从日志中:
09-27 06:37PM 12.158
com.google.truxmap.server.TruckJdoDAO addTruck: get tweeter key agp0cnV4bWFwcGVych8LEgdUd2VldGVyIhJrZXltdW5jaGllbWFjaGluZTEM
W 09-27 06:37PM 12.160
com.google.truxmap.server.TruckJdoDAO addTruck: addTruck exception: class java.lang.IllegalStateException. Message:Primary key for object of type Tweeter is null.
I cant imagine any more methods to solve my problem. Here's a thread I made yesterday that describes the parent and child class in detail: https://stackoverflow.com/questions/3800450/many-to-one-unidirectional-gae-jdo-relationship-amongst-entities
I'm trying to add a Truck and persist it, but the persistence manager insists that the primary key of the parent item is NULL, even though I log the value prior to persisting the child, and the parent is NOT null, in fact its the valid key it should be set too. Why is the persistence manager seeing something that I'm not?
try{
if (!findTruck(truck)){
_logger.warning("get tweeter key " + truck.getTweeter().getEncodedKey());
pm.makePersistent(truck);
}
}
finally {
pm.close();
}
from the logs:
09-27 06:37PM 12.158
com.google.truxmap.server.TruckJdoDAO addTruck: get tweeter key agp0cnV4bWFwcGVych8LEgdUd2VldGVyIhJrZXltdW5jaGllbWFjaGluZTEM
W 09-27 06:37PM 12.160
com.google.truxmap.server.TruckJdoDAO addTruck: addTruck exception: class java.lang.IllegalStateException. Message:Primary key for object of type Tweeter is null.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许父级不是持久状态,而是分离的?还是短暂的?为什么不打印出对象的状态
perhaps the parent is not persistent state, but is detached ? or transient? why not print out the state of the object
也许父级和子级由不同的 ObjectManager 管理。如果您使用 java,请确保父级和子级由同一管理器 (PersistenceManager) 管理。下面的代码会抛出这个异常。
Maybe the parent and the child are managed by different ObjectManager. If you use java, make sure the parent and the child are managed by the same manager (PersistenceManager). The code below would throw this exception.