4 Replies Latest reply on Jan 27, 2006 11:21 AM by ducky427

    EJB3.0 Read-only entity bean annotation

    ducky427

      Hi,
      I am new to EJB 3.0 and I wanted to know if it is possible to have a EJB3.0 container managed read-only entity bean? I have searched extensively and been unable to find any reference of it. EJB 2.1 does have it but not EJB 3.0. Is the feature yet to be implemented or am I missing out something?

      Thanks!

      ducky

        • 1. Re: EJB3.0 Read-only entity bean annotation
          ducky427

          I just realised that you could use an xml descriptor file for describing the bean. I could put the correct xml in jboss.xml and ejb-jar.xml. But then I encounter another problem. Currently I am also using EJB 2.1 beans and the ejb-jar.xml has the following line:

          <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">

          So if I were to change the file for EJB 3.0 entity bean, it would get recognised as a EJB 2.1 bean which I don't want.

          Long story short, is there a way of having 2 descriptor files: one for EJB 2.1 and another one for EJB 3.0?

          Thanks!

          • 2. Re: EJB3.0 Read-only entity bean annotation
            euvitudo

            In answer to your first question, why not just use the @Column annotation, e.g.,

            @Column(insertable=false,updatable=false)


            The ejb3 persistence spec has more details.

            • 3. Re: EJB3.0 Read-only entity bean annotation
              ducky427

              This is not what I aiming to do. The annotation:

              @Column(insertable=false,updatable=false)

              just prevents inserting & updating of the field. I was looking for a more general solution which prevents for example, the following type of query:

              SQL statement "SELECT 1 FROM ONLY "public"."name" x WHERE "id" = $1 FOR UPDATE OF x"


              Thanks
              ducky

              • 4. Re: EJB3.0 Read-only entity bean annotation
                ducky427

                I think I need to be give specific imformation to how I arrived at the problem.

                I have a few tables in postgres which I am accessing using entity beans. Some of these tables contain basic information like user names, password etc. The other tables have columns which have id's from these tables as foreign keys.

                When the JBoss server is running, I am getting the following error in the jboss log:

                2006-01-27 16:00:05,914 ERROR [org.hibernate.util.JDBCExceptionReporter] ERROR: deadlock detected
                2006-01-27 16:00:05,914 ERROR [org.hibernate.event.def.AbstractFlushingEventListener] Could not synchronize database state with session
                org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
                


                and in the database I am getting the error:

                CONTEXT: SQL statement "SELECT 1 FROM ONLY "public"."name" x WHERE "id" = $1 FOR UPDATE OF x"
                ERROR: deadlock detected
                DETAIL: Process 3177 waits for ShareLock on transaction 9349151; blocked by process 3175.
                 Process 3175 waits for ShareLock on transaction 9349149; blocked by process 3177.
                


                These transactions succedd if I send them again (as one expects).

                The problem is that the transactions which are throwing this error are not updating the name table. I just want to use a simple select query instead of a "select _____ for update of __" query.

                If I remove the foreign key constraint for name, I do not get these errors.

                This led me to thinking that having read-only entity beans for basic objects like name might solve the problem.

                Thanks

                ducky