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: non-managed entities
PostPosted: Thu Jun 14, 2007 3:49 pm 
Newbie

Joined: Sat Jun 09, 2007 9:40 am
Posts: 11
I’m trying to introduce NHibernate to a mid-sized investment bank in NYC. It seems like a nice product and I like using xml files and entities. I figured to start using only Native SQL for the first project so they don’t have a HQL learning curve. Thus far I’m filling entities, updating the db, and such.

Am I correct that non-managed entities are ones that have no persistance? Ie: you just get an plain Ilist that is not connected, linked or related to anything or any other actions. Is there another recommended way to get this type of unconnected list/whatever?

Also

I’m getting this exception on the following code:

{"Return types of SQL query were not specified [SELECT Fund_Name, Currency FROM fund]"}

Code:
IQuery sqlQuery = session.CreateSQLQuery("SELECT Fund_Name, Currency FROM fund") .SetResultTransformer(Transformers.AliasToBean(typeof(Fund)));

IList funds = sqlQuery.List();


What is causing this error. How do I specify a return type of SQL query?

Here is the mapping and type:

Code:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">

  <class name="Test.Accounting.CashTransaction.Core.Domain.Fund, CashTransaction" table="fund">
    <composite-id>
      <key-property name="ManagementCode" column="Management_Code" type="String" length="2"  />
      <key-property name="FundCode" column="Fund_Code" type="String" length ="6"/>
    </composite-id>
    <property name="FundName" column="Fund_Name" type="String" length="50" />
    <property name="Currency" type="String" length="3"/>
  </class>

</hibernate-mapping>


using System;
using System.Collections.Generic;
using System.Text;

namespace Test.Accounting.CashTransaction.Core.Domain
{
    /// <summary>
    /// Fund object for NHibernate mapped table 'Fund'.
    /// </summary>
    [Serializable]
    public class Fund
    {
        protected string _managementCode;
        protected string _fundCode;
        private string _fundName;
        private string _currency;

        public Fund()
        {
        }

        public virtual string ManagementCode
        {
            get { return _managementCode; }
            set
            {
                _managementCode = value;
            }
        }

        public virtual string FundCode
        {
            get { return _fundCode; }
            set
            {
                _fundCode = value;
            }
        }

        public virtual string FundName
        {
            get { return _fundName; }
            set
            {
                _fundName = value;
            }
        }

        public virtual string Currency
        {
            get { return _currency; }
            set
            {
                _currency = value;
            }
        }

        public override bool Equals(object obj)
        {
            return base.Equals(obj);
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
   
    }
}

[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 14, 2007 9:59 pm 
Newbie

Joined: Sat Jun 09, 2007 9:40 am
Posts: 11
Figured it out:

Code:
IQuery sqlQuery = session.CreateSQLQuery(
           "SELECT Fund_Name AS   FundName, Currency FROM fund")
                .AddScalar("FundName", NHibernateUtil.String)
                .AddScalar("Currency", NHibernateUtil.String)
                .SetResultTransformer(Transformers.AliasToBean(typeof(Fund)));


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.