1

私の問題を解決するためのこれ以上の方法を想像することはできません。親と子のクラスを詳細に説明する昨日作成したスレッドは次のとおりです: https ://stackoverflow.com/questions/3800450/many-to-one-unidirection-gae-jdo-relationship-amongst-entities

トラックを追加して永続化しようとしていますが、永続化マネージャーは、子を永続化する前に値をログに記録し、親がnullではない場合でも、親アイテムの主キーが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.
4

2 に答える 2

1

おそらく、親は永続的な状態ではありませんが、切り離されていますか? または一時的な?オブジェクトの状態を出力しない理由

于 2010-10-02T10:06:41.150 に答える
1

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.

PersistenceManager pm = JDOHelper.getPersistenceManagerFactory("transactions-optional");
Parent parent = (Parent)pm.getObjectById(Parent.class, parentKey);
pm.close();
// New object manager
pm = JDOHelper.getPersistenceManagerFactory("transactions-optional");
Child child = new Child();
child.setParent(parent);
pm.makePersistent(child); // Exception here
于 2011-07-30T16:15:53.110 に答える