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

  • Home
  • SEARCH
  • 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 1016847
In Process

The Archive Base Latest Questions

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

there are two entity classes: @Entity public class Place implements Serializable { @Id @GeneratedValue(strategy

  • 0

there are two entity classes:

@Entity
public class Place implements Serializable {
    @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id;
    @OneToMany(mappedBy = "place")
    private List<Event> events = new ArrayList<Event>();
    private String name;
//getters setters
}
@Entity
public class Event implements Serializable {
    @Id @GeneratedValue(strategy=GenerationType.IDENTITY) private Long id;
    @OneToMany(mappedBy = "event" , cascade={CascadeType.PERSIST})
    private List<Participant> participants = new ArrayList<Participant>();
    @ManyToOne(optional=false,fetch=FetchType.EAGER) private Place place;
    private String name;
// getters setters
}

the generated tables:

mysql> desc EVENT;
+----------+--------------+------+-----+---------+----------------+
| Field    | Type         | Null | Key | Default | Extra          |
+----------+--------------+------+-----+---------+----------------+
| ID       | bigint(20)   | NO   | PRI | NULL    | auto_increment |
| NAME     | varchar(255) | YES  |     | NULL    |                |
| PLACE_ID | bigint(20)   | YES  | MUL | NULL    |                |
+----------+--------------+------+-----+---------+----------------+
mysql> desc PLACE;
+----------+--------------+------+-----+---------+----------------+
| Field    | Type         | Null | Key | Default | Extra          |
+----------+--------------+------+-----+---------+----------------+
| ID       | bigint(20)   | NO   | PRI | NULL    | auto_increment |
| LOCATION | varchar(255) | YES  |     | NULL    |                |
| NAME     | varchar(255) | YES  |     | NULL    |                |
+----------+--------------+------+-----+---------+----------------+


Now, I'll code some Java so the Place and Event tables looks in this way:

+----+--------+
| ID | NAME   |
+----+--------+
|  1 | Prague |
+----+--------+
+----+-------------+----------+
| ID | NAME        | PLACE_ID |
+----+-------------+----------+
|  1 | Programming |        1 |
+----+-------------+----------+

Now, I would like to pick a place and view all its events:

// there's an ejb talking with persistence layer 
Place p = ejb.getPlaceWithId(1);


and I would think that there's something more than empty collection in p.events, but there is not - based on my observations. Why?

  • 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-16T10:36:35+00:00Added an answer on May 16, 2026 at 10:36 am

    Now, I would like to pick a place and view all its events (…) and I would think that there’s something more than empty collection in p.events, but there is not – based on my observations. Why?

    My observations are that the events are LAZY in the code you’re showing:

    @OneToMany(mappedBy = "place")
    private List<Event> events = new ArrayList<Event>();
    

    So how did you come to the conclusion that they are empty when loading a given Place exactly? Did you try to call size() on the collection to force the loading (or to iterate on collection items)?

    Regardless of the answer to the above question, my suggestions would be to

    • Activate SQL logging (and to run the queries in a SQL client if necessary) to see what is happening.
    • Maybe actually use a fetch join if you want to load the events eagerly:

      SELECT p FROM Place p join fetch p.events WHERE p.id = :id
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two entity classes: public class Invoice { public int ID { get;
Assume I have the following two classes: public class User : Entity { public
@Entity @Inheritance(strategy = InheritanceType.SINGLE_TABLE) public class Problem { @ManyToOne private Person person; } @Entity
I'm using the Entity Framework version 4.2. There are two classes in my small
I have two classes an Arc class and a Line class public class Arc
I have an entity class: Cabbage.java package womble; public class Cabbage { private int
I java ee project with two entity classes: Employee and Shift, and there's a
I have two classes. One is the entity class, the other serves as a
I have a fairly simple Many to One relationship between two classes: @Entity public
I have two classes university and department, suppose there is one to many relationship

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.