5 Replies Latest reply on Aug 11, 2005 4:24 AM by epbernard

    Should the Java transient keyword affect EJB3 persistence?

    rickmeier

      I'm experimenting with field persisted entity beans in an architecture that uses a thick client. Specifically, I'm using the Java transient keyword to control the amount of a given object graph that is serialized from the server to the client. It seems to be working in that fields defined as transient are not serialized to the client, but updates are persisted from the server to the database via the EntityManager.

      Can I count on this behavior or did I stumble upon a bug?

      Regards,
      Rick Meier

        • 1. Re: Should the Java transient keyword affect EJB3 persistenc
          bill.burke

          EJB3 persistence doesn't care if the field is marked 'transient' or not. By default all properties are considered persistent...

          use the javax.persistence.Transaction annotation on your properties/fields that you don't want mapped

          • 2. Re: Should the Java transient keyword affect EJB3 persistenc
            rickmeier

            I was hoping you would say that.

            When we use access=AccessType.FIELD, the EntityManager does indeed ignore the transient Java keyword.

            But when we use access=AccessType.PROPERTY, the EntityManager does not persist data members of the entity bean that are marked with the transient Java keyword. Sounds like a bug?

            • 3. Re: Should the Java transient keyword affect EJB3 persistenc
              bill.burke

              If AccessType.PROPERTY, then it finds/discovers the persistent props from setter/getter methods. If AccessType.FIELDS it finds/discovers by reflecting on the fields of the class.

              • 4. Re: Should the Java transient keyword affect EJB3 persistenc
                rickmeier

                So from the JBoss EJB3 container implementation perspective, would it make sense to rely on the behavior of the transient keyword or not?

                Part of what makes me nervous of doing so is that the behavior of the JBoss EntityManager is different depending on whether the entity bean is using field or property based access type. Entity beans persisted with AccessType.PROPERTY, will not persist to the database if the underlying Java data member is a transient data member (Java transient keyword not the @Transient annotation).

                The attractive part is that it is a very elegant solution, as long as it isn't an accidental side effect that may disappear in a future release of JBoss.

                Would it be possible for the EJB3.0 specification to provide a statement clarifying the behavior?

                • 5. Re: Should the Java transient keyword affect EJB3 persistenc
                  epbernard

                  The spec is clear, there is no mention of the transient keyword. We've considered this keyword as orthogonal to the ORM persistence.

                  If the implementation really behave this way, this is a bug: but I do not reproduce it. Check your code, there is probably an issue somewhere.