3 Replies Latest reply on Aug 19, 2009 8:02 AM by Prathamesh Gaddam

    Problem: OneToOne mapping?

    Prathamesh Gaddam Novice
      Dear Team,

      I'm facing a strange problem. I got two entities with one to one mapping:

      @Entity
      @Table(name = "WORK_LOG", schema = "dbo", catalog = "NEW")
      public class WorkLog extends BasePortalObject {

           @OneToOne(cascade = CascadeType.ALL, mappedBy = "workLog")
           public Timesheets getTimesheets() {
                return timesheets;
           }
      ..}

      @Entity
      @Table(name = "TIMESHEETS", schema = "dbo", catalog = "NEW")
      public class Timesheets implements java.io.Serializable {
           @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
           @JoinColumn(name = "WORK_LOG_ID")
           public WorkLog getWorkLog() {
                return workLog;
           }
      }

      When I' update the 'workLog' parent-entity vide 'workLogHome' the 'timesheets' child-entity is update/persisted.

      In debug mode the values held by workLogHome.instance is the one which need to persisted.

      However the parent/'workLog' is NOT modified/persisted, nor the update query is logged/generated.

      Even, there is no error/exception/warning towards it. Please assist to resolve/understand the problem.

      Thank you in advance.

      Note:
      1. Using seam-gen code [Seam 2.1.0,Eclipse 3.4.2,Jboss 4.3.2]
      2. Base/abstract class for entity towards role based permissions:

      public abstract class BasePortalObject implements IPortalObject, java.io.Serializable {
      .
      .
      }
        • 1. Re: Problem: OneToOne mapping?
          Prathamesh Gaddam Novice
          Dear Team,

          I'm unable to update the entity ('WorkLog') only when extending abstract class 'BasePortalObject'. Why?

          unable to trace the problem.

          One more thing the abstract class 'BasePortalObject' has a collection/set of another entity 'permission' as:

          @Entity
          @Table(...)
          public class Permission{
          ..
          }

          public abstract class BasePortalObject implements IPortalObject, java.io.Serializable {

          set<Permission> p = new HashSet<Permission>(0);
          .
          }

          Thank you in advance!
          • 2. Re: Problem: OneToOne mapping?
            Jaime Martin Apprentice

            hi,
            check if you have defined any update flag in your columns.
            For instance:


                 @OneToOne(fetch = FetchType.LAZY)
                 @JoinColumn(name = "type", nullable = true, insertable = false, updatable = false)
                 @NotNull
                 public Type getType() {
                      return type;
                 }
            



            These links may help you:


            java2s


            oracle



            • 3. Re: Problem: OneToOne mapping?
              Prathamesh Gaddam Novice
              Thank you Jaime, for the speedy reply!

              As suggested I have rechecked and confirm that I have not used the insertable/updatable flags.

              The actual problem is as per previous post http://seamframework.org/Community/ProblemOneToOneMapping#comment91585

              I'm able to update the entity using WorkLogHome.update towards:

              @Entity
              public class WorkLog {...}

              However, when is define the entity as (extending abstract class):

              @Entity
              class WorkLog extends BasePortalObject { ...}

              the update query is not generated and no modification are reflected in database. However message is generated 'Successfully Updated'.

              Note: The code snippet for the base abstract class 'BasePortalObject' is at http://seamframework.org/Community/ProblemOneToOneMapping#comment91585