0

I have an EJB accessing a MySQL database through WildFly.

In the EJB I have an Entity (Book) and a Session Bean (BookBean) that exposes methods to manage the database from within a Remote Client.

Could you show me a code example in order to contact the Entity bean using session façades from a remote client (a simple Java class)?

The only tutorial I found here is really outdated.

Michael
  • 876
  • 9
  • 29

1 Answers1

0

You can try something similar like this

public class Client{
   //Get the session bean of the Book entity bean
   @EJB private BookBean bookBean;

   public static void main(String[] args) {
      //Assume BookBean has a method named getBooks() which will return books in the database
      List<Book> booksList = bookBean.getBooks();

       System.out.println("Book(s) entered so far: " + booksList.size());
       int i = 0;
       for (Book book:booksList) {
         System.out.println((i+1)+". " + book.getName());
         i++;
      }    
   }
}
Ruchira
  • 115
  • 1
  • 2
  • 8