-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Newbie really cant help himself
PostPosted: Tue May 20, 2008 4:50 am 
Newbie

Joined: Tue May 20, 2008 3:40 am
Posts: 1
Location: Basel, Switzerland
NHibernate version:1.2.1.4000

Name and version of the database you are using:OracleDB, Oracle9Dialect

Hi Everybody, i am new to Hibernate/NHibernate and have a, how i guess, easy-to-solve-problem, but i just dont know what i am doing wrong. I rtfm and i tried the search-button but couldnt find a solution that matches my prob.

I have a 1-to-n-relation between the two tables Plan and PlanVersion. PlanVersion has a foreign key PlanId, but, because I always need the active PlanVersion, the Table Plan also has a ActivePlan, where a PlanVersionId is saved (not constrained). Now I want to load this active PlanVersion in the Object Plan:

Table create scripts:
Code:
CREATE TABLE Plan (
    PlanId INTEGER CONSTRAINT NN_Plan_PlanId NOT NULL,
    PlanName VARCHAR2(40),
    Description VARCHAR2(1000),
    ActiveVersion INTEGER,
    CONSTRAINT PK_Plan PRIMARY KEY (PlanId)
);
CREATE TABLE PlanVersion (
    PlanVersionId INTEGER CONSTRAINT NN_PlanVersion_PlanVersionId NOT NULL,
    PlanVersionIndex INTEGER,
    PlanVersion VARCHAR2(40),
    Description VARCHAR2(1000),
    Startdate DATE,
    Enddate DATE,
    Activation TIMESTAMP,
    PlanStatusId INTEGER,
    PlanId INTEGER,
    CONSTRAINT PK_PlanVersion PRIMARY KEY (PlanVersionId)
);
ALTER TABLE PlanVersion ADD CONSTRAINT Plan_PlanVersion
    FOREIGN KEY (PlanId) REFERENCES Plan (PlanId);


The classes look like this:

Code:
public class Plan
    {
        public virtual int Id { get; set; }
        public virtual string Name { get; set; }
        public virtual string Description { get; set; }
        public virtual PlanVersion ActiveVersion { get; set; }
        public virtual IList<PlanVersion> Versions { get; set; }
    }

    public class PlanVersion
    {
        public virtual int Id { get; set; }
        public virtual string Name { get; set; }
        public virtual string Description { get; set; }
        public virtual DateTime StartDate { get; set; }
        public virtual DateTime EndDate { get; set; }
        public virtual DateTime Activation { get; set; }
        public virtual PlanStatus Status { get; set; }
        public virtual Plan Plan { get; set; }
    }


The *.hbm.xml-File looks like this at the moment (tried a lot to solve it)
Code:
<class name="SampleScheduler.DataAccess.PlanData.Plan, DataAccess" table="Plan">
    <id name="Id" column="PlanId" type="int">
      <generator class="sequence">
        <param name="sequence">plansequence</param>
      </generator>
    </id>
    <property name="Name" column="PlanName" type="String"/>
    <property name="Description" type="String"/>
   
    <list name="Versions" lazy="true" cascade="save-update">
      <key column="PlanId"/>
      <index column="PlanVersionIndex"/>
      <one-to-many class="SampleScheduler.DataAccess.PlanData.PlanVersion, DataAccess"/>
    </list>   
    <one-to-one name="ActiveVersion" cascade="save-update"
    class="SampleScheduler.DataAccess.PlanData.PlanVersion, DataAccess" constrained="false" />
  </class>

  <class name="SampleScheduler.DataAccess.PlanData.PlanVersion, DataAccess" table="PlanVersion">
    <id name="Id" column="PlanVersionId" type="int">
      <generator class="sequence">
        <param name="sequence">plansequence</param>
      </generator>
    </id>
    <property name="Name" column="PlanVersion" type="String"/>
    <property name="Description" type="String"/>
    <property name="StartDate"  type="DateTime"/>
    <property name="EndDate" type="DateTime"/>
    <property name="Activation" type="Timestamp"/>
   
    <property name="Status" column="PlanStatusId" type="SampleScheduler.DataAccess.PlanData.PlanStatus, DataAccess"/>
   
    <many-to-one name="Plan" column="PlanId" class="SampleScheduler.DataAccess.PlanData.Plan, DataAccess" foreign-key="ActiveVersion"/>
  </class>

Getting the IList of Versions works fine, I just dont get it to receive the ActiveVersion with the PlanVersionId in the ActiveVersion-Field. With this code I get the following error:
Quote:
property mapping has wrong number of columns: PlanVersion.SampleScheduler.DataAccess.PlanData.PlanVersion type: Plan


I also had the error once, that there is more than one PanVersion with the same PlanId. (What has to be the case.)
How can I load the single PlanVersion with PlanVersionId of the Table Plan, Column ActiveVersion in the Property PlanVersion ActiveVersion of the object Plan? (If it is possible without the Property Plan in the PlanVersion.)

Thnx for your help and sorry if its way to easy and I just steal your time. :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.