2 Replies Latest reply on Aug 22, 2005 5:41 PM by triathlon98

    Select problem

    micmnm

      I have a problem with the fetching type for a select query. I created an entity (TableA) which has a link annotated like this:

      .....

      @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH} , fetch = FetchType.LAZY)
      @JoinColumns({@JoinColumn(name = "f_LinkField_ID", columnDefinition = "CHAR(14)")})
      public TableB getLinkField()
      {
      return linkField;
      }

      .....

      In the linked table(TableB) the join column is annotated like this:

      .....
      @OneToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH}, mappedBy = "linkField", fetch = FetchType.LAZY)
      public Collection getLinkField2()
      {
      return linkField2;
      }
      .....

      When selecting a record from TableA, hibernate generates no extra query to obtain the linked field from TableB, which is ok.

      When using a NamedQuery to obtain a record from TableB, hibernate executes an extra query to obtain the linked entity from TableA though fetch is set to lazy. When selecting a TableB record I want not be generated an extra query to select the link owner.

      Is there something wrong with the link I have created ?

      Thanks for help.