0

I use spring data, jpa and hibernate

I have a Advertisement class

@Entity
public class Advertisement implements Serializable {

  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  private Long id;

  @OneToMany(mappedBy="id", cascade={CascadeType.REMOVE}, fetch=FetchType.LAZY)
  private Set<Message> messages = new HashSet<Message>();
}

and a message class

@Entity
public class Message implements Serializable {
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  private Long id;
  @ManyToOne(fetch = FetchType.LAZY)
  private Advertisement advertisement;
}

when i search an Advertisement by id, i can see all their message... i don't understand why, i put lazy...

I search a way to load Advertisement without message.

4

1 回答 1

0

在您调用它之前,您不会加载消息。

于 2015-01-05T01:37:26.497 回答