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: A Collection of Enumerations with IQuery Help
PostPosted: Fri Nov 16, 2007 7:30 pm 
Newbie

Joined: Fri Nov 16, 2007 6:20 pm
Posts: 15
I'm using Enums to map simple bits of data for my various business objects. In most cases this work fine since I have a single value stored in the BO. One of my business objects needs to have multiple "types".

There are two relevant database tables, Projects, and ProjModes. There is actually a third that is essentially a look-ip for ProjModes, but I'm trying to replace the look-up table with an enumeration (which I've done successfully with single values).

It is the collection/list aspect that seems to be giving me problems.

Code:
public enum ProjectMode
{
    Web = 0,
    Mail,
    DataEntry,
    Phone,
    Consulting,
    DataAnalysis,
    FocusGroup,
    CognitiveIntrviews,
    Other = 100,

}


My current implementation of Project is as follows (irrelevant bits removed):
Code:
public class Project : DomainObject<int>
{
    private IList<ProjectMode> m_Modes;

    public virtual IList<ProjectMode> Modes
        {
            get { return m_Modes; }
            set { m_Modes = value;}
        }
}


The edited schema:
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" schema="dbo">
  <class name="SESRC.Scheduler.Core.Domain.Project, SESRC.Scheduler.Core" table="ut_Projects">
    <id name="ID" type="Int32" column="prKey">
      <generator class="identity" />
    </id>
<bag name="Modes" access="property" lazy="false" cascade="none" table="ut_ProjModes">
      <key column="prKey"/>
      <element column="prMode" type="SESRC.Scheduler.Core.Domain.ProjectMode, SESRC.Scheduler.Core" />
    </bag>
  </class>
</hibernate-mapping>


ProjectDao - My data access object where I'm trying to do a query on a sub-set of the Modes list. Relevant method listed:

Code:
        public IList<Project> GetAllProjects(ProjectType type)
        {

            //ArrayList projects = new ArrayList();
            IList<ProjectMode> projects = new List<ProjectMode>();
            projects.Add(ProjectMode.Mail);
            projects.Add(ProjectMode.Phone);

            IQuery query =
                NHibernateSession.CreateQuery(
                    "FROM Project as pj WHERE pj.Modes IN (:ProjectModes)");

            // Filter on type if set.
            switch (type)
            {
                case ProjectType.Funded:
                    query.SetParameterList("ProjectModes", projects);
                    break;
                case ProjectType.All:
                    break;
            }

            // Get the data
            IList<Project> projectList = query.List<Project>();

            return (IList<Project>)projectList;
        }


The problem seems to be with the IQuery handling the collection. I get this error: "unindexed collection before []". I'm not certain if it has a problem with the Modes collection or the projects collection I'm sending the IQuery.

Is there a better approach for handling a list of enumerations? Should I make it a full blown Business Object? Make some sort of ValueObject?

Any help appreciated,
Jack


Top
 Profile  
 
 Post subject: Re: A Collection of Enumerations with IQuery Help
PostPosted: Sat May 31, 2008 10:10 am 
Newbie

Joined: Sun May 04, 2008 1:10 pm
Posts: 8
jambrose wrote:
Code:
...
            IQuery query =
                NHibernateSession.CreateQuery(
                    "FROM Project as pj WHERE pj.Modes IN (:ProjectModes)");
...


I just had this problem here:

http://forum.hibernate.org/viewtopic.php?t=987309

However the short answer may be to change the above code to:

Code:
...
            IQuery query =
                NHibernateSession.CreateQuery(
                    "FROM Project as pj WHERE :ProjectModes in elements(pj.Modes)");
...


Don't forget to mark this helpful, if it is so...
Brian[/url]


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.