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 1062211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:35:24+00:00 2026-05-16T18:35:24+00:00

I managed (as you can see in older posts from me) to insert a

  • 0

I managed (as you can see in older posts from me) to insert a onetomany relation through hibernate. My two entity classes look like following:

Project.java:

@Entity
public class Project {

 @Id
 @GeneratedValue(strategy = GenerationType.IDENTITY)
 private int id; 
    @OneToMany(cascade = CascadeType.ALL, mappedBy="project")
    @OrderColumn(name = "project_index")
    List<Application> applications;
....

Application.java (which is a child of project. One project can have many applications, but one application belongs to just one project)

@Entity
public class Application {

 @Id
 @GeneratedValue(strategy = GenerationType.IDENTITY)
 private int id;
    @ManyToOne
    @JoinColumn(name = "project_id")
    private Project project;
...

So far, insertion of data works well. But getting data out of my database is the problem. I tried two ways:


Way 1: I retrieve a Project and try to get Applications out of the list attribute. But unfortunately Application entities are in a ‘storedSnapshot’, which seems pretty wrong to me. Here is a screenshot from my debug screen:

alt text

Actually that way works! I did some mistakes somewhere else…


Way 2: I try to retrieve a list of all applications via sql query:

public List<Application> getApplications(int project_id) {
  Session session = HibernateUtil.getSessionFactory().getCurrentSession();
  session.beginTransaction();
  List<Application> applications = session.createQuery("from Application a where a.project_id=" + project_id + " ").list();
  return applications;
 }

..which throws strange exception -.-

org.hibernate.QueryException: could not resolve property: project_id of: de..common.entities.Application [from de..common.entities.Application a where a.project_id=1 ]

Problem with way 2 is that that I mix up SQL and HQL.


A little help for a hibernate beginner would be great 🙂
Cheers..

  • 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-16T18:35:25+00:00Added an answer on May 16, 2026 at 6:35 pm

    You should be able to access the applications by simply:

    List<Application> applications = project.getApplications();
    

    PersistentBag is implementing java.util.List so you should not care of its internals.

    You will just need an open session to do that, otherwise a LazyInitializationException will be thrown.

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

Sidebar

Related Questions

You can use Xcode to generate a managed class of an entity. This class
Can someone tell me how to catch parameters passed from URI in JSF's managed
I managed to create a .deb file from a source program,tar.gz how can i
I'm using JSF 2.0. I have a managed bean which I can access through
Can .NET (managed code) read and write to CouchDB? I would like to build
I can't find a solution for that. I managed to solve the problem of
what exactly are un-managed and managed memory ? can anybody explain me in brief?
Having a really aggravating problem using Managed Metadata in SP2010 where I can get
From report manager we can assign new roles , but these users needs to
How can I process a va_list argument with Java, having received it from the

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.