Hibernate使用spring boot spring数据创建错误的sql

时间:2017-07-23 11:55:09

标签: hibernate jpa spring-boot spring-data-jpa

我有两个具有以下关系的实体:

@Entity
@Table(name = "tblRouters")
public class Router {
  @Id
  @Column(name = "nRouterID")
  private Integer routerId;

  @Column(name = "strRouterName")
  private String routerName;

  @Column(name = "strRouterIP")
  private String routerIp;

  @Column(name = "strLastAutomaticCheckTime")
  private String lastCheckTime;

  @Column(name = "nSupportedSnmpVersion")
  private String protocol;

  @OneToMany(fetch =FetchType.EAGER)
  @JoinColumn(name="strIpAddr", referencedColumnName="strRouterIP")
  private Set<RouterDetail> routerDetails;
}

@Entity
@Table(name = "tblRouter_Detail")
public class RouterDetail {
  @Id
  @Column(name = "nObjectId")
  private Integer objectId;

  @Column(name = "cObjectType")
  private Character objectType;

  @Column(name = "strSysName")
  private String systemName;

  @Column(name = "strDescription")
  private String systemDescription;

  @ManyToOne
  @JoinColumn(name="strIpAddr", referencedColumnName="strRouterIP")
  private Router router;
}

我只对Router具有RouterDetail.objectType价值&#39; C&#39;

的对象感兴趣。

所以我有以下存储库接口:

public interface RouterService extends CrudRepository<Router, Integer> {
  public List<Router> findByRouterDetailsObjectType(char objectType);
}

但是我发现我生成的SQL查询不正确:

select
     router0_.nRouterID as nRouterI1_23_1_,
     router0_.strLastAutomaticCheckTime as strLastA2_23_1_,
     router0_.nSupportedSnmpVersion as nSupport3_23_1_,
     router0_.strRouterIP as strRoute4_23_1_,
     router0_.strRouterName as strRoute5_23_1_,
     routerdeta1_.strIpAddr as strIpAdd6_21_3_,
     routerdeta1_.nObjectId as nObjectI1_21_3_,
     routerdeta1_.nObjectId as nObjectI1_21_0_,
     routerdeta1_.nEquipTypeId as nEquipTy2_21_0_,
     routerdeta1_.cObjectType as cObjectT3_21_0_,
     routerdeta1_.strIpAddr as strIpAdd6_21_0_,
     routerdeta1_.strDescription as strDescr4_21_0_,
     routerdeta1_.strSysName as strSysNa5_21_0_ 
from
     SWAT.dbo.tblRouters router0_ 
left outer join
     SWAT.dbo.tblObjectSWAT routerdeta1_ 
on
     router0_.strRouterIP=routerdeta1_.strIpAddr 
where
     router0_.strRouterIP=?

问题究竟在哪里?

0 个答案:

没有答案