我有:
@Entity
public class EmailAndName {
...
}
和
@Entity
public class MessageDetails {
@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinTable(name = "MessageDetails_to")
public Set<EmailAndName> getTo() {
return to;
}
}
当我
public static void main(String []a)
{
StatelessSession sess = HibernateUtils.getSessionFactory().openStatelessSession();
sess.beginTransaction();
MessageDetails messageDetails = new MessageDetails();
messageDetails.setTo(new HashSet<EmailAndName>());
EmailAndName emailAndName = (EmailAndName) sess.get(EmailAndName.class, 1L);
if (emailAndName == null ) throw new RuntimeException();
messageDetails.getTo().add(emailAndName);
sess.insert(messageDetails);
sess.getTransaction().commit();
}
未填充 MessageDetails_to 表。我应该怎么办?我不想编写本机查询。谢谢你。