-->
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.  [ 1 post ] 
Author Message
 Post subject: Inconsistent Data Structures
PostPosted: Sun Mar 18, 2012 12:14 pm 
Newbie

Joined: Sun Mar 18, 2012 12:12 pm
Posts: 1
Hi
I'm trying to build a 4-tier Web-Application in Java. I'm using the Hibernate Framework for ORM and a MySQL Database.
The table "project" has a one-to-many relation to the table "idea". What I'm trying to do, is to get a List (or Set) of Ideas using the following function:

Code:
    public static List getProjectIdeas(int projectId)
        {
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            session.beginTransaction();
            Query q = session.createQuery("from Idea where id_project=" + projectId);
            List<Idea> ideaList = (List<Idea>) q.list();
            System.out.println(ideaList.size());
            return ideaList;
        }


At first, it works fine and I get all the ideas from the database. But when I add new ideas to the project and then call the function again, I don't always get a complete list of the ideas related to the project back. The size of the list I receive from q.list() varies between the number of ideas stored in the database before the insert and the actual number of ideas.
This is the function I use to insert the Idea into the Database:

Code:
public static void writeObject(Object object)
        {
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            Transaction tx = session.beginTransaction();
            session.saveOrUpdate(object);
            tx.commit();
        } 


This is my first hibernate project, so i don't know if there is anything wrong with the config file:

Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
    <hibernate-configuration>
      <session-factory>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.url">***/ideator</property>
        <property name="hibernate.connection.username">***</property>
        <property name="hibernate.connection.password">***</property>
        <property name="hibernate.current_session_context_class">thread</property>
        <property name="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property>
        <mapping resource="mapping/Category.hbm.xml"/>
        <mapping resource="mapping/Rating.hbm.xml"/>
        <mapping resource="mapping/Idea.hbm.xml"/>
        <mapping resource="mapping/Participation.hbm.xml"/>
        <mapping resource="mapping/Project.hbm.xml"/>
        <mapping resource="mapping/Criteria.hbm.xml"/>
        <mapping resource="mapping/User.hbm.xml"/>
      </session-factory>
    </hibernate-configuration>


Thanks in advance for you help.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.