Re: Extending cayenne-class

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Thu Jan 23 2003 - 10:34:17 EST

  • Next message: Dirk Olmes: "Re: Cayenne and Hibernate"

    Hi Halbig,

    without seeing your mapping I can't say why the NPE happens, but I believe
    that I can still help you out with this problem. When you were generating
    Java classes from Cayenne, did you select "Generate Parent/Child class
    pairs checkbox"? Just like in this example:

    http://objectstyle.org/cayenne/userguide/quickstart/webapp.html#5

    If not, please do so. You will end up with 2 classes for each "Cayenne"
    persistence class. Taking your example, you will have:

    public class _CmTransaction extends CayenneDataObject {
       getXyz() { ... }
       setXyz() { ... }
       .....
    }

    public class CmTransaction extends _CmTransaction {

    }

    After this is done, you can safely put your extra methods
    ("getTimestampFormatted()") in CmTransaction without the fear that it will
    conflict with Cayenne class generation in the future. If you do it this
    way, you will NOT need any extra helper classes, and can use (and
    customize) CmTransaction directly.

    Hope this helps.

    Andrus

    > Hi,
    >
    > I' have a little question and I hope I will get some help.
    >
    > I extended a helper class from my cayenne class, because I need some
    > formatted datas so I had to overwrite the original cayenne method. I had
    > to overrwrite the constructur to get the datas in the helper. (s.below)
    >
    > public class CmTransactionHelper extends CmTransaction {
    >
    > public CmTransactionHelper(CmTransaction cmTransaction)
    > {
    > super();
    >
    > super.setAmount(cmTransaction.getAmount());
    > super.setFkAccountId(cmTransaction.getFkAccountId());
    > super.setFkUserId(cmTransaction.getFkUserId());
    > super.setFkCreatorId(cmTransaction.getFkCreatorId());
    > super.setFkTransactionTypeId(cmTransaction.getFkTransactionTypeId());
    > super.setText(cmTransaction.getText());
    > super.setTimestamp(cmTransaction.getTimestamp());
    > super.setValutaTimestamp(cmTransaction.getValutaTimestamp());
    > super.setCm_transactionAccount(cmTransaction.getCm_transactionAccount());
    > super.setCm_transactionCreator(cmTransaction.getCm_transactionCreator());
    > super.setCm_transactionTransactionType(cmTransaction.getCm_transactionTransactionType());
    > super.setCm_transactionUser(cmTransaction.getCm_transactionUser());
    > super.setDataContext(cmTransaction.getDataContext());
    > }
    >
    > public String getTimestampFormatted()
    > {
    > return Formatter.dateToString_DDMMYYYY(super.getTimestamp());
    > }
    > }
    >
    > My problem is, that I got every time a Nullpointer-Exception when I try
    > to call the methods of the relation:
    > super.setCm_transactionAccount(cmTransaction.getCm_transactionAccount());
    >
    > When I don't add the "setCm_ ..." in this constructor, I will get the
    > NullPointer-Exception from struts!!
    >
    > <logic:iterate id="transaction" name="TransactionForm"
    > property="transactionList"
    > type="com.winterthur.cm.model.CmTransactionHelper">
    > <bean:define id="transactiontextkey" name="transaction"
    > property="cm_transactionTransactionType.descriptionKey"/> <td
    > width="54%" class="centertext"><bean:message key="<%=
    > transactiontextkey.toString() %>"/>-<bean:write name="transaction"
    > property="text"/></td>
    > </logic:iterate>
    >
    > When I don't use this helper-class and fill my list whith the
    > Cayenne-class, all works fine! Any clue, what I'm doin wrong, when I
    > extended the cayenne-class?
    >
    > Thanks in advance
    > Thomas



    This archive was generated by hypermail 2.0.0 : Thu Jan 23 2003 - 10:34:17 EST