-->
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: How to implement DAO for One-To-Many?
PostPosted: Sun Apr 27, 2008 11:27 pm 
Newbie

Joined: Sun Apr 27, 2008 11:23 pm
Posts: 1
Hibernate version: not sure

Mapping documents:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="csns.model.bulletinboard">
   <!-- Forum -->
    <class name="ForumModel" table="forum">
        <id name="id" column="forum_id">
            <generator class="native" />
        </id>
        .....
        <list name="topics">
            <key column="forum_id" />
            <index column="topics_order" />
            <one-to-many class="TopicModel" />
        </list>
         .....
    </class>
   
    <!-- Topic -->
    <class name="TopicModel" table="topic">
       <id name="id" column="topic_id">
          <generator class="native" />
       </id>
         .....
        <list name="replies">
            <key column="topic_id" />
            <index column="replies_order" />
            <one-to-many class="RepliesModel" />
        </list>
    </class>
   
    <!-- Replies -->
    <class name="RepliesModel" table="replies">
       <id name="id" column="replies_id">
          <generator class="native" />
       </id>
         .....
    </class>
</hibernate-mapping>


Full stack trace of any exception that occurs:
Code:
2008-04-27 16:52:48,015 ERROR ExceptionResolver: could not resolve property: forum_id of: csns.model.bulletinboard.TopicModel [from csns.model.bulletinboard.TopicModel topic where topic.forum_id = ?]; nested exception is org.hibernate.QueryException: could not resolve property: forum_id of: csns.model.bulletinboard.TopicModel [from csns.model.bulletinboard.TopicModel topic where topic.forum_id = ?]
2008-04-27 16:52:48,015 ERROR ExceptionResolver: org.springframework.orm.hibernate3.HibernateQueryException: could not resolve property: forum_id of: csns.model.bulletinboard.TopicModel [from csns.model.bulletinboard.TopicModel topic where topic.forum_id = ?]; nested exception is org.hibernate.QueryException: could not resolve property: forum_id of: csns.model.bulletinboard.TopicModel [from csns.model.bulletinboard.TopicModel topic where topic.forum_id = ?]
Caused by: org.hibernate.QueryException: could not resolve property: forum_id of: csns.model.bulletinboard.TopicModel [from csns.model.bulletinboard.TopicModel topic where topic.forum_id = ?]



I'm trying to do a DAO implementation, but it seems that my code below is not working, that's because TopicModel doesn't have forum_id as the property in the hibernate, the forum_id is mapped as one-to-many from the ForumModel. I want to get the list of the topic in which has the same forum_id as the getParameter string that I retrieves..

Code:
   @Override
   public List getTopicByForumId(String forum_id) {
        String query = "from TopicModel topic where topic.forum_id = ?";
        return getHibernateTemplate().find(query, forum_id);
   }


Thanks a lot!!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 28, 2008 3:30 pm 
Beginner
Beginner

Joined: Tue Jun 26, 2007 2:31 pm
Posts: 21
I see that your TopicModel doesnt have a forum_id which you have been using in the Query in ur DAO soo try having a many-to-one in the mapping file for the TopicModel and then change ur query


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.