1 Reply Latest reply on Feb 9, 2007 11:42 PM by Gavin King

    Best practice for creating reference entity for entity creat

    Anthony Whitford Newbie

      I used seam-gen from 1.1.6 GA to create a reverse-engineered project. I have a table with a self join. (Note that in order to use generate-entities, I had to drop the foreign key constraint, then I doctored the generated project a bit to restore the object relationship.) My entity looks something like:

      public class Currency implements Serializable
       private static final long serialVersionUID = 1L;
       /** ISO 4217 Currency Code */
       @Column(columnDefinition = "char(3)", length = 3)
       @Length(min = 3, max = 3)
       private String code;
       /** Currency name (English) */
       @Column(length = 40, nullable = false, unique = true)
       @Length(max = 40)
       private String name;
       /** Rank for sorting */
       @Column(nullable = false)
       private int sortRank;
       * Replacement Currency. For example pre-Euro currencies would have EUR specified.
       private Currency replacementCurrency;
       * Replacement Date is the date that the currency was replaced. For example,
       * the date when the currency was converted to EUR.
       private Date replacementDate;

      So on the CurrencyEdit.xhtml page, there is code like:
       <tr class="prop">
       <td class="name">Replacement Currency</td>
       <td class="value">
       <h:inputText id="replacementCurrency"

      Of course, when I try to save, I get an argument type mismatch error:

      CurrencyEdit.xhtml @85,96 value="#{currencyHome.instance.replacementCurrency}": Exception setting property replacementCurrency of base with class com.mycompany.reference.iso.Currency, Bean: com.mycompany.reference.iso.Currency, property: replacementCurrency, argument type mismatch

      The form only is accepting a String, which is the PK of Currency, but not a Currency object. Clearly, I need to use that String key to find the object instance, and then assign that to the object being edited... Anybody have an example?

      I can imagine the code to do this, but I am really wondering what the best practice is. Can I use the CurrencyHome or CurrencyList object in some fashion, or do I need to create another bean?

      (I am a little surprised that I couldn't find an example in the Seam documentation.)