1 2 3 Previous Next 32 Replies Latest reply on Jan 27, 2003 6:30 AM by milasx Go to original post
      • 15. Re: NEW FEATURE: new ways to create entity beans
        aloubyansky

        This won't be ported in Branch_3_0, i.e JBoss-3.0.X.
        Current plans for releases:
        2002-10-25 jboss-2.4.10
        2002-10-27 jboss-3.0.4
        2002-11-03 jboss-3.2.0beta2
        2002-12-22 jboss-4.0alpha

        This feature is available since JBoss-3.2.

        • 16. Re: NEW FEATURE: new ways to create entity beans
          mozheyko_d

          Unfortunately is not present and it is not compatible at all with 3.2beta, it is required 3.2beta2 which itself I search where to take

          • 17. Re: NEW FEATURE: new ways to create entity beans
            rupinder

            in the snippet given in this thread for jbosscmp-jdbc.xml, its mentioned that :
            <!-- auto-incremented primary key (jdk1.3/1.4) for now supported only for MySQL. -->

            can you please tell for which version of MySQL it is supported?
            I am using MySQL 3.23 and it seems sequencing itself is not supported in this version.

            thanks,
            Rupinder

            • 18. Re: NEW FEATURE: new ways to create entity beans
              mdrob

              Hello Alex,

              I have a question about "unknown-pk" feature in JBoss 3.2: Does it (intend to) provide a mechanism to automatically select a reasonable implementation for unknown primary key based on the target database platform?

              It is great to have a way to fine-tune the behavior of unknown primary key, but it will be nice to have a default database-optimized behavior which does not need any jbosscmp-jdbc.xml tweaking in the majority of cases (e.g. use sequences for Oracle, autoincrement columns for MySQL, etc).

              Thanks -- Maxim.

              • 19. Re: NEW FEATURE: new ways to create entity beans
                johnwatson

                This looks like it might be what I need.

                I'm using JBoss 3.2.0 Beta 2 with Oracle 8i.  Most of my tables have a primary key named 'id' which is auto-generated by Oracle by means of an insert trigger.  These tables also have a secondary key (e.g. a column named 'code')

                My problem is how to map the columns and keys onto CMP 2.0.  My idea was to tell CMP that the ejb primary key is 'code' and to treat the 'id' field as a simple non-keyed column. Is there a way of setting up the deployment descriptor where 'id' is read only, so that Enity beans can read the value, but CMP never writes it?

                • 20. Re: NEW FEATURE: new ways to create entity beans
                  johnwatson

                  I'm also having problems using the 'pk-sql generated unknown-pk; overriding default sql' method. The Oracle sequence is called OK, but I get a Class Cast exception when CMP is checking if the type exists:

                  DEBUG [Publisher] Executing SQL: SELECT Bookmaker.NEXTVAL FROM Dual
                  DEBUG [Publisher] Create: pk=31
                  DEBUG [Publisher] Executing SQL: SELECT COUNT(*) FROM PUBLISHER WHERE id=?
                  ERROR [Publisher] Error checking if entity exists
                  java.lang.ClassCastException

                  The id column is an Oracle Number(12) type that I presume maps to BIGINT and java Long. So I have defined my auto-generating pk entity as:



                  <ejb-name>Publisher</ejb-name>
                  <table-name>PUBLISHER</table-name>
                  <unknown-pk>
                  <unknown-pk-class>java.lang.Long</unknown-pk-class>
                  <column-name>id</column-name>
                  <jdbc-type>BIGINT</jdbc-type>
                  <sql-type>NUMBER(12)</sql-type>
                  </unknown-pk>
                  <entity-command name="pk-sql">
                  SELECT seq_Bookmaker.NEXTVAL FROM Dual
                  </entity-command>


                  What am I doing wrong? Thanks in advance for any advice you can give.

                  • 21. Re: NEW FEATURE: new ways to create entity beans
                    johnwatson

                    Got a bit further by a) reducing size of id column to Number(10) and redefining as a java.lang.Integer in the , and b) upgrading to the 9i JDBC implementation (ojdbc14.jar) - it appears to have been predominantly an Oracle problem in classes12.zip. But now... CMP is attempting to write NULL to my id column:

                    DEBUG [Publisher] Executing SQL: SELECT Bookmaker.NEXTVAL FROM Dual
                    DEBUG [Publisher] Create: pk=40
                    DEBUG [Publisher] Executing SQL: SELECT COUNT(*) FROM PUBLISHER WHERE id=?
                    DEBUG [Publisher] Executing SQL: INSERT INTO PUBLISHER (id, name, description, code) VALUES (?, ?, ?, ?)
                    ERROR [Publisher] Could not create entity
                    java.sql.SQLException: ORA-01400: cannot insert NULL into ("BETEDIT"."PUBLISHER"."ID")

                    Can anyone help???

                    • 22. Re: NEW FEATURE: new ways to create entity beans
                      aloubyansky

                      I believe PK is generated and set correctly looking at the log and code.
                      Is there a chance that some non-pk field is set to null while it can't be?

                      alex

                      • 23. Re: NEW FEATURE: new ways to create entity beans
                        aloubyansky

                        I think it also could happen if unknown pk is incorrectly defined in DDs. Could you post the relevant snippets?

                        alex

                        • 24. Re: NEW FEATURE: new ways to create entity beans
                          aloubyansky

                          Sorry, still sleeping...
                          The above snippet for unkown-pk looks ok. Note, that id must not appear among cmp fields. Confirm this, please.

                          alex

                          • 25. Re: NEW FEATURE: new ways to create entity beans
                            johnwatson

                            Thanks very much for replying, Alex.

                            Sorry - what I didn't tell you in my last 2 posts was that I'd changed my strategy. Now 'id' is the primary key (both in the bean and on the table) and 'code' is an alternate key. I am still attempting to auto-generate the id value declaratively (in the entity section by reference to the Oracle sequence). So with this strategy, I need to define id as a CMP field, otherwise the bean won't load. Presumably this approach is NOT called an unknown-pk by JBoss CMP(but what is it?).

                            I don't mind reverting to my original strategy (where 'code' is the primary key of the bean and id is still auto-generated) but I do need to provide a getter for id in this case.

                            I think I'm confused about the difference between these 2 cases as far as JBoss CMP is concerned. I'd prefer to use the strategy where id is the primary key of the bean.

                            Sorry to have misled you.

                            • 26. Re: NEW FEATURE: new ways to create entity beans
                              aloubyansky

                              unknown-pk means unknown PRIMARY KEY. So, it must be primary key, not just CMP field.
                              And unknown pk doesn't have abstract accessors. Check the spec for "Primary Keys Special Case" or so.

                              You can fetch the value of generated unknown pk with EntityContext.getPrimaryKey and then cast it to the actual type.

                              Indeed, in case of MySQL you can have auto-incremented "known" primary key.
                              <cmp-field>
                              <field-name>id</field-name>
                              <column-name>knownid</column-name>
                              <jdbc-type>INTEGER</jdbc-type>
                              <sql-type>INTEGER(11)</sql-type>
                              <auto-increment/>
                              </cmp-field>
                              <entity-command name="mysql-get-generated-keys"/>
                              Where id is a CMP primary key with abstract accessors.
                              But currently it's supported only with MySql.

                              We could add support for other vendors. But it requires me to install different DBs and learn their specific JDBC API. I would like to work on other stuff if you would like to implement this for other vendors, I could guide you. It shouldn't be too difficult.
                              Let me know if you are interested loubyansky@ua.fm

                              alex

                              • 27. Re: NEW FEATURE: new ways to create entity beans
                                johnwatson

                                Thanks very much for this full reply Alex. Afraid I'm still struggling after trying to follow your advice. I removed the cmp-field and the primkey-field for id from the dd, removed the abstract accessors for id, and my entity description looks like this (still trying to call an Oracle sequence):

                                <unknown-pk>
                                <unknown-pk-class>java.lang.Integer</unknown-pk-class>
                                <column-name>id</column-name>
                                <jdbc-type>INTEGER</jdbc-type>
                                <sql-type>INTEGER</sql-type>
                                </unknown-pk>
                                <!-- entity command to create the entity -->
                                <entity-command name="pk-sql">
                                SELECT seq_Bookmaker.NEXTVAL FROM Dual
                                </entity-command>


                                ejbCreate now fails because it can't construct a where clause when checking if the entity exists:

                                DEBUG [org.jboss.plugins.cmp.jdbc.JDBCPkSqlCreateCommand.Publisher] Executing SQL: SELECT seq_Bookmaker.NEXTVAL FROM Dual
                                DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCPkSqlCreateCommand.Publisher] Create: pk=484
                                DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCPkSqlCreateCommand.Publisher] Executing SQL: SELECT COUNT(*) FROM PUBLISHER WHERE
                                ERROR [org.jboss.ejb.plugins.cmp.jdbc.JDBCPkSqlCreateCommand.Publisher] Error checking if entity exists
                                java.sql.SQLException: ORA-00921: unexpected end of SQL command

                                Also, I'm still unsure how to provide a getter for id. I can get the id from the PK in the bean, but how to I expose it in a method call to a client? Does CMP allow you to define non-CMP methods?

                                I'll contact you directly about contributing to the JBoss code.

                                • 28. Re: NEW FEATURE: new ways to create entity beans
                                  aloubyansky

                                  By the spec unknown pk must be of type java.lang.Object.
                                  ejbCreate returns Object, findByPrimaryKey takes Object as a param and prim-key-class in ejb-jar.xml must also be java.lang.Object. Check it.

                                  >Also, I'm still unsure how to provide a getter for id. I
                                  >can get the id from the PK in the bean, but how to I
                                  >expose it in a method call to a client? Does CMP allow
                                  >you to define non-CMP methods?
                                  Yes, sure, e.g.
                                  public com.MyType getPk()
                                  {
                                  (com.MyType)ctx.getPrimaryKey();
                                  }

                                  alex

                                  • 29. Re: NEW FEATURE: new ways to create entity beans
                                    johnwatson

                                    Thanks very much, Alex .... I'm slowly beginning to understand. I've done what you suggest, and now ejbCreate works fine, and I can provide a concrete getter for id. The only slight surprise to me is that the unknown primary key has turned out to be a BigDecimal, whereas in the entity unknown-pk-class I defined it as an Integer.

                                    I'll now move on to test the finder methods.