I`m using Eclipse RCP with EJB exposed like WebServices. My services beans looks like follows
@Override
@SuppressWarnings("unchecked")
public List<Author> listAll() {
final Query query = this.entityManager.createQuery("from Author");
final List<Author> authors = query.getResultList();
return authors;
}
The two entityes are:
@Entity
@Table(name = "books")
public class Book implements Serializable {
@Id
private int id;
private String title;
private String summary;
private String isbn;
@Column(name = "published")
private Date publishingDate;
@Column(name = "created")
private Date createdAt;
@Column(name = "updated")
private Date modifiedAt;
@ManyToMany
@JoinTable(
name = "book_authors",
joinColumns = @JoinColumn(name = "book_id", referencedColumnName = "id"),
inverseJoinColumns = @JoinColumn(name = "author_id", referencedColumnName = "id"))
private List<Author> authors;
and
@Entity
@Table(name = "authors")
public class Author implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private int id;
@Column(name = "first_name")
private String firstName;
@Column(name = "middle_name")
private String middleName;
@Column(name = "last_name")
private String lastName;
@Column(name = "created")
private Date createdAt;
@Column(name = "updated")
private Date modifiedAt;
@ManyToMany
@JoinTable(
name = "book_authors",
joinColumns = @JoinColumn(name = "author_id", referencedColumnName = "id"),
inverseJoinColumns = @JoinColumn(name = "book_id", referencedColumnName = "id"))
private List<Book> books;
In my TestWSCLient i`m trying to do something like this
AuthorServiceBeanServiceLocator locator = new AuthorServiceBeanServiceLocator();
AuthorServiceBean service = locator.getAuthorServiceBeanPort();
Author[] authors = service.listAll();
for(Author a : authors){
System.out.println(a.getFirstName());
}
and I`m getting this error
{....//xml.apache.org/axis/}stackTrace:Marshalling Error: failed to lazily initialize a collection of role: ro.cgs.entities.Author.books, no session or session was closed
I`m mention that if I do not make the Many-To-Many relationship all works fine. Can anybody tell me what should I do to fix this problem ? I use Hibernate for persistence. Thanks.