-->
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.  [ 3 posts ] 
Author Message
 Post subject: Learning HQL
PostPosted: Fri Jun 23, 2006 12:56 pm 
Newbie

Joined: Mon Jun 19, 2006 1:14 pm
Posts: 6
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" auto-import="false" namespace="Devtoo.Data" assembly="Devtoo.Data">
<class name="Devtoo.Data.Article" table="tblArticle" lazy="false">
<id name="ArticleId" column="ArticleId" unsaved-value="0">
<generator class="identity"></generator>
</id>
<property name="Title"></property>
<property name="SubmitDate"></property>
<property name="Body"></property>
<property name="AuthorId"></property>
<property name="Diggs"></property>
<many-to-one name="Author" class="Devtoo.Data.User" column="AuthorId" insert="false" update="false"></many-to-one>
<many-to-one name="Queue" class="Devtoo.Data.ArticleQueue"></many-to-one>
<bag name="Comments" generic="true">
<key column="ArticleId"></key>
<one-to-many class="Devtoo.Data.ArticleComment"></one-to-many>
</bag>
</class>
</hibernate-mapping>


<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" auto-import="false" namespace="Devtoo.Data" assembly="Devtoo.Data">
<class name="Devtoo.Data.ArticleQueue" table="tblArticleQueue" lazy="false">
<id name="ArticleQueueId" column="ArticleQueueId" unsaved-value="0">
<generator class="identity"></generator>
</id>
<property name="ArticleId"></property>
<property name="ApprovedDate"></property>
<property name="EditorId"></property>
</class>
</hibernate-mapping>

[Serializable]
public class Article
{
private int articleId;
public int ArticleId
{
get { return articleId; }
set { articleId = value; }
}
private string title;
public string Title
{
get { return title; }
set { title = value; }
}
private DateTime submitDate;
public DateTime SubmitDate
{
get { return submitDate; }
set { submitDate = value; }
}
private string body;
public string Body
{
get { return body; }
set { body = value; }
}
private ArticleQueue queue;
public ArticleQueue Queue
{
get { return queue; }
set { queue = value; }
}
private Guid authorId;
public Guid AuthorId
{
get { return authorId; }
set { authorId = value; }
}
private int diggs;
public int Diggs
{
get { return diggs; }
set { diggs = value; }
}
private IList<ArticleComment> comments;
public IList<ArticleComment> Comments
{
get { return comments; }
set { comments = value; }
}
private User author;
public User Author
{
get { return author; }
set { author = value; }
}
public Article() { }
}



and i'm doing the following query:
public static IList GetLatestArticles(int amount)
{
IQuery iquery = DatabaseFactory.Session.CreateQuery(String.Format(@"SELECT TOP {0} a FROM Article a INNER JOIN a.Queue", amount));
return iquery.List();
}


and i'm getting the error:
NHibernate.ADOException : could not load an entity: [Data.Article#1] Invalid column name 'Queue'


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 26, 2006 9:33 pm 
Regular
Regular

Joined: Wed Jun 21, 2006 3:13 pm
Posts: 110
Can you successfully load a Queue object on it's own?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 26, 2006 10:36 pm 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
Code:
<many-to-one name="Author" class="Devtoo.Data.User" column="AuthorId" insert="false" update="false"></many-to-one>
<many-to-one name="Queue" class="Devtoo.Data.ArticleQueue"></many-to-one>


your m-1 definition for Queue is missing the column name so NH is assuming the column is the same as the property. I suspect your table uses QueueID instead:

Code:
<many-to-one name="Author" class="Devtoo.Data.User" column="AuthorId" insert="false" update="false"></many-to-one>
<many-to-one name="Queue" class="Devtoo.Data.ArticleQueue" column="QueueID"></many-to-one>


or whatever the column name in your tblArticle table that relates to tblArticleQueue.


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