English 中文(简体)
用于“无所有权的许多人与许多关系”的物体
原标题:Object isnt saved for Unowned Many to Many relation

I have an unowned Many to Many relationship setup in JDO by adding the List in both the Persistence Capable objects. For the sake of explaining my problem lets call these two entities with .

实体A和实体B

Now, when i have a new Object of EntityB to be attached to the Object of EntityA, i append that Key to the EntityA object and call makePersistent on it, which saves the object. I verified that by printing it on the console.

Since, this is a Many to Many relation, i have to do the same on the other end of the relation as well. So, i fetch all the objects of EntityB which are referred by EntityA using select from " + clazz.getName()+ " where :keys.contains(key) and passing it the List of Keys which are present in Object of EntityA.

碰到的问题是,返回的物体是低温的,因此,即使将实体A的钥匙贴上单列物体,它们也有意节省到数据库中。

I am a newbie in JDO and GAE, and have been facing this problem since yesterday. Can someone please shed some light on this? I can provide sample code if needed too.

最佳回答

这里是法典

@PersistenceCapable
public class Objective {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
@Persistent
private boolean active;
@Persistent
private int corporate;
@Persistent
private String nameOfObjective;
@Persistent
private String shortDescription;
@Persistent
private int status;

@Persistent
private List<Key> scoreCardKeys; //List of Keys of Scorecards.


@PersistenceCapable
public class Scorecard {

@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;

@Persistent
private boolean active;
@Persistent
private int corporate; // synonymous to being public 
@Persistent
private Date creationDate;
@Persistent
private String nameOfScorecard;
@Persistent
private String shortDescription;

@Persistent
private Key createdUserKey;

@Persistent
private List<Key> objectiveKeys; // List of Keys of Objectives

目标实体和计分卡实体拥有许多与许多人的关系。

此处是更新记分卡的处理器方法。

public ScoreCardRepresentation updateScoreCard(ScoreCardRepresentation scoreCardRepresentation) {
    Scorecard scoreCard = scoreCardTransformer
            .transformRtoEForSave(scoreCardRepresentation);

    scoreCard.setCreationDate(new Date());

    Scorecard updatedScoreCard = scoreCardDAO.saveScoreCard(scoreCard); /*     Update the scorecard, this already has the list of Key of Objectives in it, Hence blindly save it. */

/* Update the Key of the scorecard in the Objectives too */       
updateRelatedObjectivesToScoreCard(scoreCardRepresentation,updatedScoreCard);




private void updateRelatedObjectivesToScoreCard(
        ScoreCardRepresentation scoreCardRepresentation,
        Scorecard updatedScoreCard) {
List<String> addedObjectivesIds =  scoreCardRepresentation.getAddedObjectiveKeys();
List<String> deletedObjectivesIds =  scoreCardRepresentation.getRemovedObjectiveKeys();

    // Add ScoreCard to the newly added Objectives
    if(addedObjectivesIds != null && addedObjectivesIds.size()>0){

Scorecard sc = scoreCardDAO.findScoreCardById(Scorecard.class, updatedScoreCard.getKey());
        List<Key> objKeys = sc.getObjectiveKeys();

        List<Objective> objectives = objectiveDAO.findObjectivesByKeys(Objective.class,objKeys);

页: 1 使用了从“+ clazz.getName()+”中选取的电梯:keys.contains(key)

        for(Objective obj : objectives){
            List<Key> scoreCardKeys = obj.getScoreCardKeys();
            if(scoreCardKeys != null){
                scoreCardKeys.add(sc.getKey());
            } else { 
                scoreCardKeys = new ArrayList<Key>();
                scoreCardKeys.add(sc.getKey());
            }
            obj.setScoreCardKeys(scoreCardKeys);
            Objective updatedObjective = objectiveDAO.saveObjective(obj);
            System.out.println(new ObjectiveProcessor().viewObjective(KeyFactory.keyToString(obj.getKey())));
        }
    }

    //Remove Scorecard entries from Objective. 
    if(deletedObjectivesIds != null && deletedObjectivesIds.size()>0){
        List<Objective> objectives = objectiveDAO.findObjectivesByIds(Objective.class,deletedObjectivesIds);
        for(Objective obj : objectives){
            List<Key> scoreCardKeys = obj.getScoreCardKeys();
            if(scoreCardKeys != null){
                scoreCardKeys.remove(updatedScoreCard.getKey());
            } 
            obj.setScoreCardKeys(scoreCardKeys);
        }
    }
}

能够实现的是,在使用<条码>恢复目标时** 最终目标 i 背后空洞物体,因此,必须打电话make Transient,以便它们能够坚持下去,否则它们就忽视了makePersistent方法电话。

问题回答

暂无回答




相关问题
How to make logging.debug work on Appengine?

I m having a tough time getting the logging on Appengine working. the statement import logging is flagged as an unrecognized import in my PyDev Appengine project. I suspected that this was just an ...

gqlQuery returns object, want list of keys

Is there a way to convert the GqlQuery object to an array of keys, or is there a way to force the query to return an array of keys? For example: items = db.GqlQuery("SELECT __key__ FROM Items") ...

Integrating Google AppEngine with a Thick Client

I want to make a multi-user client-server solution with Java Swing thick client as a front-end and Google AppEngine (Java one) as a back-end. The problem is that GAE provides only web-based forms for ...

sorl.thumbnail : thumbnail is not a valid tag library?

I am trying to install sorl.thumbnail but am getting the following error message: thumbnail is not a valid tag library: Could not load template library from django.templatetags.thumbnail, No module ...

热门标签