0 Replies Latest reply on Sep 12, 2007 11:15 AM by Sebastian Brosch

    Mysterios persistence problem

    Sebastian Brosch Newbie

      Hello,

      i`m having an mysterios problem with my 3tier application.
      I hope someone can give me a hint cause i'm really getting nuts.

      The problem:

      I have two tables in an oneToOne relationship.
      In my application is a mask which needs values from both tables.
      So lookup the first entityObject from the database and then call it`s
      method to get the second one.
      In a second mask i can create these objects.
      The saving works fine and all the data is written correctly into the tables.

      When i do the described lookup on the data i get the first object but the
      function which should return the related object always returns NULL.
      The data in the tables is as far as i can tell correct.

      The mysterios about this thing is that data which i write per hand into the
      database is return correctly.
      The problem occurs only if the data was entered with my application.
      I tested it and even if i enter the data written by the application exactly with
      sqlplus it works only with the second way.

      I hope it is clear what`s my problem.

      The tables in Oracle 10:

      create table campaign_context (
       campaign_context_id number,
       campaign_name varchar2(30),
       market_id number,
       brand_name varchar2(30),
       active number(1),
       description varchar2(2047),
       campaign_id number
      )
      
      create table campaign (
       campaign_id number,
       campaign_context_id number,
       campaign_name varchar2(30),
       campaign_type varchar2(30),
       summary_flag varchar2(30),
       start_date date,
       end_date date,
       external_id number,
       username varchar2(30),
       password varchar2(30),
       service varchar2(30),
       description varchar2(2047),
       scheduler_id number
      )
      
      CREATE SEQUENCE campaign_context_sequence
       START WITH 1
       INCREMENT BY 1
      
      CREATE SEQUENCE campaign_sequence
       START WITH 1
       INCREMENT BY 1
      
      ALTER TABLE campaign
      add CONSTRAINT campaign_pk PRIMARY KEY (campaign_id)
      
      ALTER TABLE campaign_context
      add CONSTRAINT campaign_context PRIMARY KEY (campaign_context_id)
      
      ALTER TABLE campaign_context
      add CONSTRAINT campaign_context_campaign_fk FOREIGN KEY (campaign_id) REFERENCES campaign(campaign_id)
      


      Source code:

      Campaign_Context:
      @Entity
      @Table(name = "CAMPAIGN_CONTEXT")
      @SequenceGenerator(name = "campaign_context_sequence", sequenceName = "campaign_context_sequence")
      @NamedQueries({@NamedQuery(name = "CampaignContext.findByCampaignContextId", query = "SELECT c FROM CampaignContext c WHERE c.campaignContextId = :campaignContextId"), @NamedQuery(name = "CampaignContext.findByCampaignName", query = "SELECT c FROM CampaignContext c WHERE c.campaignName = :campaignName"), @NamedQuery(name = "CampaignContext.findByBrandName", query = "SELECT c FROM CampaignContext c WHERE c.brandName = :brandName"), @NamedQuery(name = "CampaignContext.findByActive", query = "SELECT c FROM CampaignContext c WHERE c.active = :active"), @NamedQuery(name = "CampaignContext.findByDescription", query = "SELECT c FROM CampaignContext c WHERE c.description = :description")})
      public class CampaignContext implements Serializable {
       @Id
       @GeneratedValue(strategy=GenerationType.SEQUENCE, generator = "campaign_context_sequence")
       @Column(name = "CAMPAIGN_CONTEXT_ID", nullable = false)
       private Integer campaignContextId;
       @Column(name = "CAMPAIGN_NAME")
       private String campaignName;
       @Column(name = "BRAND_NAME")
       private String brandName;
       @Column(name = "ACTIVE")
       private Short active;
       @Column(name = "DESCRIPTION")
       private String description;
       @Column(name = "MARKET_ID")
       private Integer marketId;
       @JoinColumn(name = "CUSTOMER_ID", referencedColumnName = "CUSTOMER_ID")
       @ManyToOne
       private Customer customerId;
       @OneToOne(cascade={CascadeType.REMOVE})
       @JoinColumn(name="CAMPAIGN_ID", referencedColumnName = "CAMPAIGN_ID")
       private Campaign campaign;
      


      Campaign:
      @Entity
      @Table(name = "CAMPAIGN")
      @SequenceGenerator(name = "campaign_sequence", sequenceName = "campaign_sequence")
      @NamedQueries({@NamedQuery(name = "Campaign.findByCampaignId", query = "SELECT c FROM Campaign c WHERE c.campaignId = :campaignId"), @NamedQuery(name = "Campaign.findByCampaignName", query = "SELECT c FROM Campaign c WHERE c.campaignName = :campaignName"), @NamedQuery(name = "Campaign.findByCampaignType", query = "SELECT c FROM Campaign c WHERE c.campaignType = :campaignType"), @NamedQuery(name = "Campaign.findBySummaryFlag", query = "SELECT c FROM Campaign c WHERE c.summaryFlag = :summaryFlag"), @NamedQuery(name = "Campaign.findByStartDate", query = "SELECT c FROM Campaign c WHERE c.startDate = :startDate"), @NamedQuery(name = "Campaign.findByEndDate", query = "SELECT c FROM Campaign c WHERE c.endDate = :endDate"), @NamedQuery(name = "Campaign.findByExternalId", query = "SELECT c FROM Campaign c WHERE c.externalId = :externalId"), @NamedQuery(name = "Campaign.findByUsername", query = "SELECT c FROM Campaign c WHERE c.username = :username"), @NamedQuery(name = "Campaign.findByPassword", query = "SELECT c FROM Campaign c WHERE c.password = :password"), @NamedQuery(name = "Campaign.findByService", query = "SELECT c FROM Campaign c WHERE c.service = :service"), @NamedQuery(name = "Campaign.findByDescription", query = "SELECT c FROM Campaign c WHERE c.description = :description")})
      public class Campaign implements Serializable {
       @Id
       @GeneratedValue(strategy=GenerationType.SEQUENCE, generator = "campaign_sequence")
       @Column(name = "CAMPAIGN_ID", nullable = false)
       private Integer campaignId;
       @Column(name = "CAMPAIGN_NAME")
       private String campaignName;
       @Column(name = "CAMPAIGN_TYPE")
       private String campaignType;
       @Column(name = "SUMMARY_FLAG")
       private String summaryFlag;
       @Column(name = "START_DATE")
       @Temporal(TemporalType.DATE)
       private Date startDate;
       @Column(name = "END_DATE")
       @Temporal(TemporalType.DATE)
       private Date endDate;
       @Column(name = "EXTERNAL_ID")
       private BigInteger externalId;
       @Column(name = "USERNAME")
       private String username;
       @Column(name = "PASSWORD")
       private String password;
       @Column(name = "SERVICE")
       private String service;
       @Column(name = "DESCRIPTION")
       private String description;
       @OneToOne(cascade={CascadeType.ALL})
       @JoinColumn(name="SCHEDULER_ID", referencedColumnName = "SCHEDULER_ID")
       private Scheduler scheduler;
       @OneToOne(cascade={CascadeType.REMOVE})
       @JoinColumn(name="CAMPAIGN_ID", referencedColumnName = "CAMPAIGN_ID")
       private CampaignContext campaignContext;
      


      The error occurs in the second line:
      campaign = bean.getCampaign(id);
      campaignContext = campaign.getCampaignContext();
      


      I hope someone understands my problem and can give me a hint.
      Thanks in advance