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.  [ 7 posts ] 
Author Message
 Post subject: have anyone seen this behaviar?
PostPosted: Mon May 17, 2010 3:30 pm 
Newbie

Joined: Wed May 05, 2010 1:16 pm
Posts: 7
i have an abstract class that has 4 subclasses here is the xml below

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="TProDataTransferObjects" assembly="TProDataTransferObjects" auto-import="true">
<class name="ProjectActivity" abstract="true" table="PROJECT_ACTIVITY" lazy="false">
<id name="ProjectID" column="PROJ_ID">
<generator class="assigned"/>
</id>
<discriminator column="ACTIVITY_ID" type="string" />
<property column="ACTIVITY_ID" name="ActivityID"></property>
<property column="last_dml_dttm" name="LastUpdateDate"></property>

<subclass name="CST" discriminator-value="CST">
<join table="PROJECT_CST">
<key column="PROJ_ID"/>
<property name="dmlUser" column="LAST_DML_USER"/>
</join>
</subclass>


<subclass name="PE" discriminator-value="PE">
<join table="PROJECT_PE">
<key column="PROJ_ID"/>
<property name="dmlUser" column="LAST_DML_USER"/>
</join>
</subclass>


<subclass name="ROW" discriminator-value="ROW">
<join table="PROJECT_ROW">
<key column="PROJ_ID"/>
<property name="dmlUser" column="LAST_DML_USER"/>
</join>
</subclass>


<subclass name="UTIL" discriminator-value="UTL">
<join table="PROJECT_UTL">
<key column="PROJ_ID"/>
<property name="dmlUser" column="LAST_DML_USER"/>
</join>
</subclass>

</class>
</hibernate-mapping>


here is the code behind

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Runtime.Serialization;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

namespace TProDataTransferObjects
{
[Serializable]
[DataContract(Namespace = "TProDataTransferObjects")]
public abstract class ProjectActivity
{
[DataMember]
public virtual string ProjectID { get; set; }

[DataMember]
public virtual string ActivityID { get; set; }

[DataMember]
public virtual string LastUpdateDate { get; set; }

}

[Serializable]
[DataContract(Namespace = "TProDataTransferObjects")]
public class CST : ProjectActivity
{
[DataMember]
public virtual string dmlUser { get; set; }
}


[Serializable]
[DataContract(Namespace = "TProDataTransferObjects")]
public class PE : ProjectActivity
{
[DataMember]
public virtual string dmlUser { get; set; }
}


[Serializable]
[DataContract(Namespace = "TProDataTransferObjects")]
public class ROW : ProjectActivity
{
[DataMember]
public virtual string dmlUser { get; set; }
}


[Serializable]
[DataContract(Namespace = "TProDataTransferObjects")]
public class UTIL : ProjectActivity
{
[DataMember]
public virtual string dmlUser { get; set; }
}

}



when i run this below

[OperationContract]
public IList<ProjectExts> ViewCurrentProjects(string ProjectID)
{
using (ISession session = NHibernateContext.Current().Session)
{
IQuery query;
var sql = "from ProjectExts a " +
" inner join fetch a.Activities c " +
" inner join fetch a.NewProjectTable b " +
" inner join fetch a.UserTable d " +
" where a.ProjectID =:ProjectID " +
" and c.LastUpdateDate =(select max(LastUpdateDate) from a.Activities " +
" where a.ProjectID =:ProjectID)";


query = session.CreateQuery(sql)
.SetParameter("ProjectID", ProjectID);
IList<ProjectExts> project = query.List<ProjectExts>();

return project;

}

}

the funny behaviar is that it loops 4 times but the data is loaded into project, but no object returns.. i still do not know why is it looping 4 times.. project is populated fine with all classes and according to activity id i get the right record back from database but it is looping 4 times and every time project is populated... but still no xml returns...i have been trying to figure this our for 4 days now and i am new to nhibernate.... thanks

here is project ext class

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="TProDataTransferObjects" assembly="TProDataTransferObjects" auto-import="true">
<class name="ProjectExts" table="project_exts" lazy="false">
<id name="ProjectID" column="proj_id" type="string">
<generator class="assigned"/>
</id>

<property column="manager_empid" name="ManagerEmpId"></property>
<property column="cons_status_code" name="ConsStatCode"></property>
<one-to-one class="NewProjects" name="NewProjectTable"></one-to-one>
<one-to-one class="Users" name="UserTable" foreign-key="ManagerEmpId" ></one-to-one>

<set name="Activities" lazy="true">
<key column="proj_id" />
<one-to-many class="ProjectActivity"/>
</set>

</class>
</hibernate-mapping>

this is mapped to project activity, the one that is an abstract class..


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Runtime.Serialization;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Collections;



namespace TProDataTransferObjects
{
[Serializable]
[DataContract(Namespace = "TProDataTransferObjects")]
public class ProjectExts
{
[DataMember]
public string ProjectID { get; set; }

[DataMember]
public string ManagerEmpId { get; set; }

[DataMember]
public string ConsStatCode { get; set; }

[DataMember]
public NewProjects NewProjectTable { get; set; }

[DataMember]
public Users UserTable { get; set; }

[DataMember]
public ICollection<ProjectActivity> Activities { get; set; }

}}


Top
 Profile  
 
 Post subject: Re: have anyone seen this behaviar?
PostPosted: Wed May 19, 2010 2:28 am 
Beginner
Beginner

Joined: Fri Feb 27, 2009 6:07 am
Posts: 38
Location: Moscow,Russia
You must also define KnownType.
See sample:http://codeplex.com/NHibernateWCF


Top
 Profile  
 
 Post subject: Re: have anyone seen this behaviar?
PostPosted: Wed May 19, 2010 2:38 pm 
Newbie

Joined: Wed May 05, 2010 1:16 pm
Posts: 7
do i have to? it is working without it.


Top
 Profile  
 
 Post subject: Re: have anyone seen this behaviar?
PostPosted: Thu May 20, 2010 2:24 am 
Beginner
Beginner

Joined: Fri Feb 27, 2009 6:07 am
Posts: 38
Location: Moscow,Russia
Quote:
[OperationContract]
public IList<ProjectExts> ViewCurrentProjects(string ProjectID)

can not return type distinct from ProjectExts, if you do not define KnownType.


Top
 Profile  
 
 Post subject: Re: have anyone seen this behaviar?
PostPosted: Thu May 20, 2010 9:49 am 
Newbie

Joined: Wed May 05, 2010 1:16 pm
Posts: 7
ok thanks, where do i need to define the known type? give me an example please...


Top
 Profile  
 
 Post subject: Re: have anyone seen this behaviar?
PostPosted: Thu May 20, 2010 10:19 am 
Beginner
Beginner

Joined: Fri Feb 27, 2009 6:07 am
Posts: 38
Location: Moscow,Russia
section Web.config from this example:http://nhibernatewcf.codeplex.com
Code:
<system.runtime.serialization>
      <dataContractSerializer>
         <declaredTypes>
            <add type="NHibernateServices.AbstractEntity,NHibernateServices">
          <knownType type="NHibernateEntity.Log,NHibernateEntity"/>
          <knownType type="NHibernateEntity.Role,NHibernateEntity"/>
          <knownType type="NHibernateEntity.User,NHibernateEntity"/>
          <knownType type="TradeDemo.Customer,TradeDemo"/>
          <knownType type="TradeDemo.Product,TradeDemo"/>
          <knownType type="TradeDemo.Order,TradeDemo"/>
            </add>
         </declaredTypes>
      </dataContractSerializer>
   </system.runtime.serialization>
   <system.serviceModel>


Top
 Profile  
 
 Post subject: Re: have anyone seen this behaviar?
PostPosted: Thu May 20, 2010 3:24 pm 
Newbie

Joined: Wed May 05, 2010 1:16 pm
Posts: 7
actually i added it to the base class before defining and it worked. thanks a bunch

[DataContract(Namespace = "TProDataTransferObjects")]
-here is what i added knowntype....
public abstract class ProjectActivity


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.