• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

compilation error when comping entity bean

 
Jerret Halter
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to compile my entity bean I wrote and I am getting the following error:

CustomerBean.java:54: getFirstName() is already defined in CustomerBean
public abstract String getFirstName();
^
CustomerBean.java:55: setFirstName(java.lang.String) is already defined in CustomerBean
public abstract void setFirstName(String firstName);
^
CustomerBean.java:56: getLastName() is already defined in CustomerBean
public abstract String getLastName();
^
3 errors

Here is my code:



I have set my JAVA_HOME variable to ver 1.4
I have set my J2EE_HOME variable to ver 1.3.1
I have also set my CLASS_PATH variable to to the correct j2ee.jar
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your virtual persistent fields don't need concrete methods. The link between the fields and the persistent store's records is defined in the deployment descriptor. So just remove those concrete getter/setters :


(you also forgot to pass the lastName in setLastName)
 
Jerret Halter
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, but why in Head First EJB page 318 they have concrete methods for the virtual persistent fieldss?
 
Freddy Wong
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Okay, but why in Head First EJB page 318 they have concrete methods for the virtual persistent fields?


Actually, the setter/getter methods in page 318 are meant to be accessed by the client using the component interface. The virtual persistent fields are the ones implemented by the container.

Let's slightly modify your CustomerBean class.


If your client code needs to invoke the persistent fields, it will use setFirst()/getFirst() or setLast()/getLast() instead of setFirstName()/getFirstName() or setLastName()/getLastName(). Just think of them as business methods in your bean class.
 
Celinio Fernandes
Ranch Hand
Posts: 549
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and anyways you cannot define 2 times in a class a method with the same input parameters and the same return parameters.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic