javax.persistence.PersistenceException:没有为类java.util.GregorianCalendar注册的ScalarType

时间:2017-11-14 06:32:35

标签: java playframework

这个错误是什么意思? -

  

javax.persistence.PersistenceException:没有为类java.util.GregorianCalendar注册的ScalarType

对于以下代码,我收到上述错误。 需要帮助来解决这个问题。

 public void updateStepsFromTheConnectedApp(User user) {
    String key = "AppSync" + user.getUserId();
    Map<String, String> appSyncStatusMap = MemcacheManager.getSession(key);
    boolean isRunning = false;
    if (appSyncStatusMap != null && appSyncStatusMap.containsKey("syncRunning")) {
        String status = appSyncStatusMap.get("syncRunning");
        if (status.equalsIgnoreCase("true"))
            isRunning = true;
    }

    if (!isRunning) {
        Map<String, String> appSyncMap = new HashMap<>();
        appSyncMap.put("syncRunning", "true");
        MemcacheManager.setAppSyncSession(key, appSyncMap);
        Organization org = Ebean.find(Organization.class).where().eq("org_id",user.getOrgId()).findUnique();
        System.out.println("app used = " + user.getPedometerAppUsed());
        if (user.getPedometerAppUsed() != null && user.getPedometerAppUsed().equalsIgnoreCase("moves")) {
            AppsUsedInOrg appsUsed = Ebean.find(AppsUsedInOrg.class).where().eq("org_id",user.getOrgId()).findUnique();
            if(appsUsed.isMoves()) {
                MovesManager.getInstance().getNumberOfStepsFromMovesAndUpdate(user,org.getStepsLimit());
                normalization(user.getUserId());
            }
        } else if (user.getPedometerAppUsed() != null && user.getPedometerAppUsed().equalsIgnoreCase("fitbit")) {
            AppsUsedInOrg appsUsed = Ebean.find(AppsUsedInOrg.class).where().eq("org_id",user.getOrgId()).findUnique();

            if(appsUsed.isFitbit()) {
                FitbitManager.getInstance().getNumberOfStepsFromFitbitAndUpdate(user,org.getStepsLimit());
                normalization(user.getUserId());
            }
        } else if (user.getPedometerAppUsed() != null && user.getPedometerAppUsed().equalsIgnoreCase("misfit")) {
            AppsUsedInOrg appsUsed = Ebean.find(AppsUsedInOrg.class).where().eq("org_id",user.getOrgId()).findUnique();
            if(appsUsed.isMisfit()) {
                MisfitManager.getInstance().getNumberOfStepsFromMisfitAndUpdate(user,org.getStepsLimit());
                normalization(user.getUserId());
            }
        } else if (user.getPedometerAppUsed() != null && user.getPedometerAppUsed().equalsIgnoreCase("garmin")) {
            AppsUsedInOrg appsUsed = Ebean.find(AppsUsedInOrg.class).where().eq("org_id",user.getOrgId()).findUnique();
            if(appsUsed.isGarmin()) {
                GarminManager.getInstance().getNumberOfStepsFromGarminAndUpdate(user,org.getStepsLimit());
                normalization(user.getUserId());
            }
        } else if (user.getPedometerAppUsed() != null && user.getPedometerAppUsed().equalsIgnoreCase("GoogleFit")) {
            AppsUsedInOrg appsUsed = Ebean.find(AppsUsedInOrg.class).where().eq("org_id",user.getOrgId()).findUnique();
            if(appsUsed.isGoogleFit()) {
                GoogleFitManager.getInstance().getNumberOfStepsFromGfitAndUpdate(user,org.getStepsLimit());
                normalization(user.getUserId());
            }
        } else if (user.getPedometerAppUsed() != null && user.getPedometerAppUsed().equalsIgnoreCase("neura")) {
            AppsUsedInOrg appsUsed = Ebean.find(AppsUsedInOrg.class).where().eq("org_id",user.getOrgId()).findUnique();
            if(appsUsed.isNeura()) {
                NeuraManager.getInstance().getNumberOfStepsFromNeuraAndUpdate(user,org.getStepsLimit());
                normalization(user.getUserId());
            }
        }
        appSyncMap.put("syncRunning", "false");
        MemcacheManager.setAppSyncSession(key, appSyncMap);
    }
}
public static void normalization(long userId){

    //get user, get orgId of user, get stepsLimit of org,

    User user = UserManager.getUser(userId);
    long orgId = user.getOrgId();
    //List<User> users = Ebean.find(User.class).where().eq("user_id",userId).findList();

    Competition competition = Ebean.find(Competition.class).where().eq("orgId",orgId).findUnique();

    long limit = stepslimit(orgId);

    //        Map<Date,String> deductedScoreMap = new HashMap<>();
    //        Map<Date,String> incrementedScoreMap = new HashMap<>();

    // get last 3 days

    SimpleDateFormat dt1 = new SimpleDateFormat("yyyy-MM-dd");
    Calendar today = Calendar.getInstance();
    Calendar yesterday = Calendar.getInstance();
    yesterday.add(Calendar.DAY_OF_MONTH,-1);
    Calendar daybeforeyesterday = Calendar.getInstance();
    daybeforeyesterday.add(Calendar.DAY_OF_MONTH,-2);


        String cd = dt1.format(competition.getStartDate());

        //get the activity of last 3 days, so 3 entries, 3 lists

            List<PhysicalActivity> activity = Ebean.find(PhysicalActivity.class)
                    .where()
                    .eq("user_id", user.getUserId()).eq("date", today)
                    .eq("date",yesterday).eq("date",daybeforeyesterday)
                    .ge("date",cd).eq("type", "steps")
                    .ne("source", null)
                    .findList();

            //for this 3 lists, get steps count from physical activity table

            for (PhysicalActivity physicalActivity : activity) {
                long count = physicalActivity.getCount();
                long creditedScore = getScore(user.getUserId(), physicalActivity.getDate());
                double score1 = 0;
                long score = 0;
                //long validSteps = 0;
                if (count > limit) {
                  //  validSteps = limit;
                    score1 = limit / 50;
                    score = Math.round(score1);

                } else {
                   // validSteps = count;
                    score1 = count / 50;
                    score = Math.round(score1);
                }

                //if this score greater than already given score, then delete all the entries in scoring data table
                // of that date fetching from physical activity table.
                // and make a new entry in scoring data table with the updated score

                if (score > creditedScore) {
                    deleteScoringData(user.getUserId(), physicalActivity.getDate());
                    ScoringData scoreData = new ScoringData();

                    String dt11 = dt1.format(physicalActivity.getDate());


                    try {
                        scoreData.setDate(dt1.parse(dt11));
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                    scoreData.setOrgId(orgId);
                    scoreData.setScore(score);
                    scoreData.setType("Steps");
                    scoreData.setUserId(user.getUserId());
                    Ebean.save(scoreData);

                    long userScore = user.getScore();

                    double diff = score - creditedScore;

                    double newscore = diff + (double) userScore;
                    user.setScoreDouble(newscore);
                    user.setScore((int) newscore);

                    Ebean.save(user);

                    //incrementedScoreMap.put(physicalActivity.getDate(),""+validSteps+":"+diff);
                }


                //if this score less than already given score, then delete all the entries in scoring data table
                // of that date fetching from physical activity table.
                // and make a new entry in scoring data table with the updated score

                if (score < creditedScore) {
                    deleteScoringData(user.getUserId(), physicalActivity.getDate());
                    ScoringData scoreData = new ScoringData();
                    String dt11 = dt1.format(physicalActivity.getDate());


                    try {
                        scoreData.setDate(dt1.parse(dt11));
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                    scoreData.setOrgId(orgId);
                    scoreData.setScore(score);
                    scoreData.setType("Steps");
                    scoreData.setUserId(user.getUserId());
                    Ebean.save(scoreData);

                    long userScore = user.getScore();

                    double diff = creditedScore - score;

                    double newscore = (double) userScore - diff;
                    user.setScoreDouble(newscore);
                    user.setScore((int) newscore);

                    Ebean.save(user);

                   // deductedScoreMap.put(physicalActivity.getDate(), "" + validSteps + ":" + diff);
                }
            }

StepsManager代码:

{{1}}

0 个答案:

没有答案