Hello,
Having passed my
Java Programmer II exam last month I am now diving into the world of java EE, meaning I am quite a newbie on both Java and EE.
Currently I am trying to implement an example from the book "Beginning Java EE 6 platform with glassfish" from scratch with NetBeans.
The goal is to create a stateless enterprise bean BookEJB that implements a remote interface with createBook(book) and deleteBook(book) methods.
CreateBook should persist the book in a mySql database and deleteBook should delete it from the database.
An Enterprise Application client will remotely call createBook and deleteBook.
Book is an entity class.
I am following the process described in
https://netbeans.org/kb/docs/javaee/entappclient.html.
However this example does not involve passing an entity class while invoking the remote methods.
This is exactly where I am getting into trouble..
What I have done:
1) Create a new Java - Java Class Library project "BookRemote" for the remote interface, e.g.
2) Create a Java EE - Enterprise Application project named "BookEnterpriseApp" with a
EJB module "BookEnterpriseApp-ejb"
3) Create a new glassfish
JDBC resource on the enterprise app and import the resulting glassfish-resources.xml as a resource on glassfish. Ping successful.
4) Create a new stateless session bean inside BookEnterpriseApp-ejb, called BookEJB while checking checkbox remote in project BookRemote:
4) Create the Book Entity.
I decided to add the Book entity inside the BookRemote project, since it is needed in the interface methods that I need to add:
I did not create a persistence.xml in BookRemote since when I try that I cannot choose the JDBC resource I have added earlier.
This results in warning "project does not contain a persistence unit" on the line @Entity in Book.java.
5) Add a persistence.xml inside BookEnterpriseApp-ejb that refers to the jdbc resource:
6) Create a new Java EE - Enterprise Application Client project named "BookClient", and call BookEJB methods as follows:
7) Deploy and run the client app.
This results in exceptions:
...
java.lang.reflect.InvocationTargetException
...
Caused by: java.lang.IllegalArgumentException: Object: avt.book.entity.Book[ id=null ] is not a known Entity type.
My Questions:
- Should I indeed add the book entity inside the BookRemote project?
- if yes, what should I change to prevent the execption?