JPA:应该为主键字段定义一个非只读映射

时间:2019-05-17 16:05:10

标签: jpa mapping eclipselink

尝试运行我的应用程序时出现//@version=3 strategy("ABC", shorttitle="ABC", initial_capital=1000, commission_type = strategy.commission.percent, commission_value = 0.075, overlay = true, linktoseries = true) nominal = 1000/close // create a variable with time of exit timeExit = 0.0 timeExit := nz(timeExit[1]) msToHours(timeMs) => timeMs / 1000 / 60 / 60 isMoreThan4H() => msToHours(time - timeExit) >= 4 // detect the exit if strategy.position_size < strategy.position_size[1] timeExit := time SL = 0.0 SLold = nz(SL[1]) SL := max(max(max(strategy.position_avg_price,ohlc4)-atr(10)*3, strategy.position_avg_price * 0.96), SLold) buy = cci(close,40)<50 testPeriodStart = timestamp(2018,2,1,0,0) if time >= testPeriodStart strategy.entry("Long", strategy.long, nominal, when = buy and isMoreThan4H()) // Here added a check that is more than 4h since last exit strategy.exit("Exit", "Long", stop = SL) plot(SL, color = #006400) 错误。我看过类似的问题,但我不知道自己在做什么错。

我尝试使用Embeddable,但是由于我不知道自己在做什么,所以这还会引发错误,这使我尝试使用ClassId。但是现在我也遇到了错误,我也不知道是什么原因造成的。

实体类

private boolean saveFile(ResponseBody body, String fileName, String id) {
        final int final_id = Integer.parseInt(id);
        Intent activityIntent = new Intent(this, MainActivity.class);
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, activityIntent, 0);
        final NotificationCompat.Builder notification = new NotificationCompat.Builder(this, CHANNEL_2_ID)
                .setSmallIcon(R.drawable.ic_cloud_minload_black_24dp)
                .setContentTitle("Download")
                .setOnlyAlertOnce(true)
                .setContentText("Downloading......")
                .setPriority(NotificationCompat.PRIORITY_LOW)
                .setContentIntent(contentIntent);

        notificationManager.notify(final_id, notification.build());
        try {
            File futureStudioIconFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_minLOADS), fileName);

            InputStream inputStream = null;
            OutputStream outputStream = null;

            try {
                byte[] fileReader = new byte[4096];
                long fileS = body.contentLength();
                long fileDonwloaded = 0;

                inputStream = body.byteStream();
                outputStream = new FileOutputStream(futureStudioIconFile);

                while (true) {
                    int read = inputStream.read(fileReader);

                    if (read == -1) {
                        break;
                    } 
                    outputStream.write(fileReader, 0, read);

                    fileDonwloaded += read;

                    Long fileSD = fileDonwloaded;
                    Long fileS     = fileS;
                    int min = fileSD.intValue();
                    int max  = fileS.intValue();
                    int max2 = max - 1000000;
                    if( max2 > min) { 
                        notification.setProgress(max, min, false);
                        notificationManager.notify(final_id, notification.build());
                    } else {  
                        Intent notificationIntent = new Intent(getApplicationContext(), MainActivity.class);
                        String id_d = Integer.toString(final_id);
                        notificationIntent.putExtra("ID" , id_d);
                        notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                        PendingIntent pendingNotificationIntent = PendingIntent.getActivity(getApplicationContext(),0,notificationIntent,PendingIntent.FLAG_UPDATE_CURRENT);

                        notification.setContentText("Downnload Finished");
                        notification.setProgress(0, 0, false);
                        notification.setSmallIcon(R.drawable.ic_cloud_done_black_24dp);
                        notification.setOngoing(false);
                        notification.setAutoCancel(true);
                        notification.setContentIntent(pendingNotificationIntent);
                        notificationManager.notify(final_id, notification.build());
                    }
                }
                return true;
            } catch (IOException e) {
                return false;
            } finally {
                if (inputStream != null) {
                    inputStream.close();
                }

                if (outputStream != null) {
                    outputStream.close();
                }
            }
        } catch (IOException e) {
            return false;
        } 
    }

主键类

An internal error occurred accessing the primary key object [class domein.PersoonSessieKey].
Internal Exception: java.lang.NoSuchMethodException: domein.PersoonSessieKey.getPersoon()

1 个答案:

答案 0 :(得分:2)

IdClass的属性应与您实体中用@Id注释的字段匹配。在您发布的代码中显然不是这种情况。

domein.PersoonSessieKey.getPersoon()是预期的(但未找到),因为您有一个persoon注释为Id的属性

使其与idclass方法配合使用

  • 将与idclass中相同的字段添加到实体中,并使用@Id进行注释
  • 从关系中删除@Id
  • 将关系标记为不可更新且不可插入(以解决帖子标题中的问题,即多个可写字段映射到同一列)