hi
i save an Advertisement object,
after i save message
i try to access message from Advertisement but it's null
test unit
why ads.getMessages() is not return messages?
thanks
i save an Advertisement object,
after i save message
i try to access message from Advertisement but it's null
Code:
@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;
}
@Entity
public class Message implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@ManyToOne
private Advertisement advertisement;
}
Code:
Advertisement ads = new Advertisement();
ads = advertisementRepo.save(ads);
assertNotNull(ads);
assertNotNull(ads.getId());
Message message = new Message();
message.setAdvertisement(ads);
message = msgRepo.save(message);
ads = advertisementRepo.findOne(ads.getId());
ads.getMessages(); //return null
thanks