Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7676393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:11:21+00:00 2026-05-31T17:11:21+00:00

I’m trying to build a 4-tier Web-Application in Java. I’m using the Hibernate Framework

  • 0

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:

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:

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:

<?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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T17:11:22+00:00Added an answer on May 31, 2026 at 5:11 pm

    Ok, I was able to fix the bug. Apparently, it was not a good idea to use getCurrentSession. Better manage the session by yourself:

    Session session = HibernateUtil.getSessionFactory().openSession();
           Transaction tx = null;
           Idea idea = null;
    
           try {
               tx = session.beginTransaction();
               idea = (Idea) session.get(Idea.class, id);
               tx.commit();
           } catch (Exception e) {
               if(tx != null) {
                   tx.rollback();
               }
           } finally {
               session.flush();
           }
    
           return idea;
    

    Case closed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
We're building an app, our first using Rails 3, and we're having to build
I have thousands of HTML files to process using Groovy/Java and I need to
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.