3 Replies Latest reply on Oct 10, 2007 9:17 AM by pmuir

    Weird entity behavior

    swd847

      I have some entities, call them Portfolio and Account

      Account is the root of a single table inheritance heirachy.

      Portfolio has a OneToMany bidirectional relationship to a Account, mapped using a foreign key in Account.

      if i call portfolio.getAccounts() the accounts do not get initialized properly. All the primitive properties of Account are initialized but not relationships to entities that have already been loaded (or something like this, I am not 100% sure).

      So if I take one of the Account's that I got using portfolio.getAccounts() and call account.getPortfolio() it will return null. Same with other entities that are loaded (e.g. Acccount has a List of AccountTransactions, I can call account.getAccountTransactions() no problems but not accountTransaction.getAccount()).

      Does anyone know what could be causing this? There is nothing special about the entities and apart from this one problem everything else works fine.

        • 1. Re: Weird entity behavior

          Are you sure you have your relationship set to be bidirectional?

          • 2. Re: Weird entity behavior
            swd847

            Yes, especially because Account actually has the foreign key, and the relationships work fine in both directions normally.

            The only time there is a problem is if the entity is first loaded by portfolio.getAccounts(). If the entity has already been loaded getAccounts() works fine.

            • 3. Re: Weird entity behavior
              pmuir

              Make sure you are using the most recent hibernate annotations. Ask on the hibernate forum and have a testcase if possible.