很多关系没有得到保存

时间:2015-10-28 00:01:42

标签: jpa spring-data spring-data-jpa

我没有成功地尝试保存多对多关系。

在我的房客类

$ find * -type f -name '*.mp4' -exec ffmpeg -i {} -c copy -aspect 16:9 copy-{} ";"

# almost same outputs several times here.

ffmpeg version N-50911-g9efcfbe Copyright (c) 2000-2013 the FFmpeg developers
  built on Mar 13 2013 21:26:48 with gcc 4.7.2 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetype --enable-libgsm --enable-libilbc --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib
  libavutil      52. 19.100 / 52. 19.100
  libavcodec     55.  0.100 / 55.  0.100
  libavformat    55.  0.100 / 55.  0.100
  libavdevice    54.  4.100 / 54.  4.100
  libavfilter     3. 45.103 /  3. 45.103
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '24.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isomavc1
    creation_time   : 2012-11-01 13:42:12
    encoder         : HandBrake 0.9.8 2012071700
  Duration: 00:24:58.62, start: 0.000000, bitrate: 474 kb/s
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 640x256, 341 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 180k tbc
    Metadata:
      creation_time   : 2012-11-01 13:42:12
    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 127 kb/s
    Metadata:
      creation_time   : 2012-11-01 13:42:12

在我的联系班级

@ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, mappedBy = "lodger")
private List<Contact> contactList;

我如何保存关系

@ManyToMany
@JoinTable(name = "lodger_contact", joinColumns = @JoinColumn(name = "contact_id"), inverseJoinColumns = @JoinColumn(name = "lodger_id"))
private List<Lodger> lodger;

在我进行保存之前,我尝试向lodger添加2个联系人并删除一个。在保存之前,我看到getContactList中有2个元素。

当我进行保存时,不会进行任何查询。

1 个答案:

答案 0 :(得分:1)

由于这是双向关系,因此您应该链接/取消链接关系的两侧。您只是从一侧更新关系 - 从Lodger侧。