Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/372.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在hibernate中使用联接注释时无法获取控制器的结果_Java_Spring_Hibernate_Rest_Join - Fatal编程技术网

Java 在hibernate中使用联接注释时无法获取控制器的结果

Java 在hibernate中使用联接注释时无法获取控制器的结果,java,spring,hibernate,rest,join,Java,Spring,Hibernate,Rest,Join,我不熟悉hibernate,并试图实现hibernate的连接注释,但面临着这个奇怪的问题。由于我在运行控制器时附加了POJO,因此没有看到任何输出,但在user_song_rel表中填充了一个新行,作为song表的外键。 此外,尽管song表中有对应于song_ID的条目,但该条目的值为null(在MySQL屏幕截图中)。 请查找两个表的附加架构。 提前感谢:) 架构结构 用户歌曲映射 @NamedQueries({ @NamedQuery( name="fi

我不熟悉hibernate,并试图实现hibernate的连接注释,但面临着这个奇怪的问题。由于我在运行控制器时附加了POJO,因此没有看到任何输出,但在user_song_rel表中填充了一个新行,作为song表的外键。 此外,尽管song表中有对应于song_ID的条目,但该条目的值为null(在MySQL屏幕截图中)。 请查找两个表的附加架构。 提前感谢:)

架构结构

用户歌曲映射

@NamedQueries({
    @NamedQuery(
            name="findUserSongByUserID",
            query="from UserSongRel usr where usr.user_id = :user_id"
            )
})

@Entity
@Table(name="user_song_rel")
public class UserSongRel {
    public UserSongRel() {
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int usr_id;
    private String user_id;
    private String song_id;
    private String song_src;
    private int song_state;

    @Temporal(TemporalType.TIMESTAMP)
    private Date add_date;


    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(referencedColumnName = "song_id")
    private SongInfo songInfo;

@Entity(name=“song\u info”)
公共类歌曲信息{
@身份证
私人弦乐歌曲识别码;
私有字符串s_名称;
私人弦乐演奏家;
私人弦乐专辑;
私有整数持续时间;
私人日期相关日期;
私人投资;
@OneToMany(mappedBy=“songInfo”)
private List usersongrelist=new ArrayList();
控制器

    @RequestMapping(value = "/getUserSongs/{uid}", method = RequestMethod.GET, produces  = "application/json")
    public ResponseEntity<?> getUserSongs(@PathVariable String uid,
            HttpServletResponse response, HttpServletRequest request){
          SongInfo usr= songService.getUserSongs(uid);
          return ResponseEntity.ok().body(usr);


    }
@RequestMapping(value=“/getUserSongs/{uid}”,method=RequestMethod.GET,products=“application/json”)
public ResponseEntity getUserSongs(@PathVariable String uid,
HttpServletResponse响应,HttpServletRequest请求){
songinfousr=songService.getUserSongs(uid);
返回ResponseEntity.ok().body(usr);
}

公共歌曲信息getUserSongs(字符串uid){ 会话s=sf.getCurrentSession(); UserSongRel-songs=s.get(UserSongRel.class,1); List songList=new ArrayList(); 歌曲列表。添加(歌曲); 返回songList.get(0.getSongInfo(); } 运行控制器后选择查询。

    @RequestMapping(value = "/getUserSongs/{uid}", method = RequestMethod.GET, produces  = "application/json")
    public ResponseEntity<?> getUserSongs(@PathVariable String uid,
            HttpServletResponse response, HttpServletRequest request){
          SongInfo usr= songService.getUserSongs(uid);
          return ResponseEntity.ok().body(usr);


    }
    public SongInfo getUserSongs(String uid) {

        Session s = sf.getCurrentSession();
        UserSongRel songs=s.get(UserSongRel.class, 1);
        List<UserSongRel> songList =new ArrayList<UserSongRel>();
        songList.add(songs);
        return songList.get(0).getSongInfo();

    }