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.  [ 2 posts ] 
Author Message
 Post subject: Interface to map Properties to ObjectDataSource
PostPosted: Wed Feb 11, 2009 11:18 am 
Regular
Regular

Joined: Wed Feb 11, 2009 10:58 am
Posts: 55
Hello,
Maybe I'll find some help in here.

My Problem:

I want to map the objects created by NHibernate to a DataGridView. The Problem is not all objects do look the same. My idea was that the objects now implement an Interface (IVisualizableTeststep) that's implements getters and setters, but Hibernate doesn't let me implement the interface.

Here are my classes:

Teststep Superclass
Code:
public abstract class Teststep
  {
    public virtual String Name { get; set; }
    public virtual String Keyword { get; set; }
    public virtual Decimal Id { get; set; }
    public virtual Decimal IsVirtual { get; set; }
    public virtual Decimal Position { get; set; }
    public virtual Module Parent { get; set; }

    public Teststep()
    {
      IsVirtual = 0;
    }

  }


and i have several child classes which look like the following two:

MeasureVoltage child class
Code:
public class MeasureTeststep : Teststep
  {
    public virtual double UpperLimit { get; set; }
    public virtual double LowerLimit { get; set; }
    public virtual String MeasurePosition { get; set; }
    public virtual String Currency { get; set; }

    public MeasureTeststep()
      : base()
    {

    }
  }

public class MeasureVoltage : MeasureTeststep
  {
    public MeasureVoltage()
      : base()
    {

    }

    public MeasureVoltage(double lowerLimit, double upperLimit, String measurePosition, VoltageCurrencies currency)
      : base()
    {
      LowerLimit = lowerLimit;
      UpperLimit = upperLimit;
      MeasurePosition = measurePosition;
      switch (currency)
      {
        case VoltageCurrencies.V: Currency = "V";
          break;

        case VoltageCurrencies.mV: Currency = "mV";
          break;
      }
    }
}


SendCommand child class
Code:
public class SendCommand : Teststep
  {
    public virtual String Command { get; set; }
    public virtual String Answer { get; set; }

    public SendCommand()
    {
      Command = "";
      Answer = "";
    }
  }


The mapping file for this classes:

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="ETToolV2" namespace="Continental.ETTool">
  <class abstract="true" name="Teststep" table="ET_TESTSTEP">
    <id name="Id" column="ID_TESTSTEP" type="Decimal">
      <generator class="sequence">
        <param name="ET_TESTSTEP_SEQ"/>
      </generator>
    </id>
    <discriminator column="TESTSTEP_TYPE" type="String" />
    <property name="Name" type="String" column="DESCRIPTION" />
    <property name="Keyword" type="String" column="KEYWORD" />
    <property name="IsVirtual" type="Decimal" column="IS_VIRTUAL" />
    <property name="Position" type="Decimal" column="POSITION" not-null="true"/>
    <many-to-one name="Parent" not-null="true" column="ID_MODULE" />
    <subclass name="SendCommand" discriminator-value="0">
      <property name="Command" type="String" column="PARAMETER0" />
      <property name="Answer" type="String" column="PARAMETER1" />
    </subclass>
    <subclass name="MeasureTeststep" abstract="true">
      <property name="LowerLimit" type="Double" column="PARAMETER0" />
      <property name="UpperLimit" type="Double" column="PARAMETER1" />
      <property name="MeasurePosition" type="String" column="PARAMETER2" />
      <property name="Currency" type="String" column="PARAMETER3" />
      <subclass name="MeasureVoltage" extends="MeasureTeststep" discriminator-value="10"/>
    </subclass>
  </class>
</hibernate-mapping>


Hope I haven't forgot anything, but this works fine.

Now if I try to do something like:

Code:
public interface IVisualizableTeststep
  {
    String Name { get; set; }
    String Keyword { get; set; }
    String Parameter0 { get; set; }
    String Parameter1 { get; set; }
  }
}


Now I try to implement the interface:

Code:
public class SendCommand : Teststep, IVisualizableTeststep
  {
    public virtual String Command { get; set; }
    public virtual String Answer { get; set; }

    public virtual Parameter0
    {
      get{return Command;}
      set{Command = value;}
    }

    public virtual Parameter1
    {
      get{return Answer;}
      set{Answer = value;}
    }

    public SendCommand()
    {
      Command = "";
      Answer = "";
    }
  }


Now I get an Error from Hibernate telling me that set_Parameter0() should be virtual...

anybody got an idea how I could solve this? I'm relatively new to NHibernate. If anybody got another idea how I could map the objects to a DataGridView please let me know.

Thanks for your help,
Florian Fanderl


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 12, 2009 4:00 am 
Regular
Regular

Joined: Wed Feb 11, 2009 10:58 am
Posts: 55
oookkk... don't know what the problem was yesterday, but today it works fine -.-

I hate it if I don't know what was wrong, but thanks to everybody who has read this thread!!!

Greetings,
Reflection


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

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.