2 Replies Latest reply on Jun 29, 2009 5:22 AM by wolfgangknauf

    EJB3 entity inheritance override getter in subclass

    asafz

      Hi,
      I have an abstract entity bean class that have a string member named user:

      private String user;

      public String getUser(){
      return user;
      }

      In one of the subclasses I want to override the getUser method to do the following:

      public String getUser(){
      if (user == null){
      return "nullUser";
      }

      reutrn user;
      }


      I'm receiveing an Exception from jboss that I cannot override this method.

      Is it allowed to override bean getters? what is the correct way to do it?

      thanks

        • 1. Re: EJB3 entity inheritance override getter in subclass
          asafz

          I changed t he code a little (wanted to create a workaround) and moved the getUser method to the father class.

          I'm still having the following problem:
          I dont want that the "nullUser" will be persist to the database, I just want it to be virtually returned to the user when the real user is null
          but jboss is persisting this value to the database anyway (even tough I'm not setting the member just returning this value in the getter)

          Is there any way to do such a thing? return a value in a bean getter that will not get persist?

          is there a way to add a member + getter/setter in indicate him as not persistable?

          Is there a way to deattach a single bean (not all EM with clear)?

          thanks

          • 2. Re: EJB3 entity inheritance override getter in subclass
            wolfgangknauf

            Hi,

            where did you place the @Column annotations? On the field or on the getter/setter? Or did you use the JBoss defaults? You might try to place them on the field instead of the getter, then it will hopefully get the persisted value from the field, not from the property. Note that this would change the field/property access for all properties of this entity, not just for the single field.

            is there a way to add a member + getter/setter in indicate him as not persistable?

            Sure, use the @Transient annotation.

            Unfortunately, I cannot answer your last question.

            Best regards

            Wolfgang