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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:44:27+00:00 2026-06-08T06:44:27+00:00

My entity contains the following private ForeignCollection attribute: @ForeignCollectionField private ForeignCollection<Order> orderCollection; private List<Order>

  • 0

My entity contains the following private ForeignCollection attribute:

@ForeignCollectionField
private ForeignCollection<Order> orderCollection;

private List<Order> orderList;

What is the best way or usual way to avoid a having a caller use a ForeignCollection? Is there any neat way to return the Collections data to a caller?

How does the following method look? It allows a caller to access the data via a List. Would you recommend doing it this way?

public List<Order> getOrders() {
    if (orderList == null) {
        orderList = new ArrayList<Order>();
        for (Order order : orderCollection) {
            orderList.add(order);
        }
    }
    return orderList;
}
  • 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-06-08T06:44:28+00:00Added an answer on June 8, 2026 at 6:44 am

    If it’s ok to change the signature to Collection rather than List, you could try using Collections.unmodifiableCollection().

    public Collection<Order> getOrders()
    {
        return Collections.unmodifiableCollection(orderCollection);
    }
    

    Otherwise, your approach of using a lazy member variable is fine (provided you don’t need synchronization). Also, note that you can just use the constructor of ArrayList to copy the values from the source collection:

    orderList = new ArrayList<Order>(orderCollection);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the three following classes: EntityTransformer contains a map associating an Entity with a
I have the following Entities; Ticket contains a set of 0,N WorkOrder: @Entity public
I have an entity that contains a list of other entities. The list of
in an app i have an entity that contains a list of other entities
I have a simple XCDataModel that contains one Entity with One Attribute. Essentially, I
I have an abstract entity called Block which contains two attributes: column and order
Say I have the following method: private static void SetLastModifiedTimeUser<TEntity>(TEntity entity) where TEntity :
I have written the following code: @Entity @Table(name=person) @Inheritance(strategy=InheritanceType.JOINED) public class Person { private
For entity ParentEntity with a collection of type ChildEntity which contains an Order property
I've got the entity that contains @version field. Sometimes I need to update it

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.