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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:21:48+00:00 2026-06-08T09:21:48+00:00

Sorry if duplicated. Is it possible or recommended for business layer to using objects

  • 0

Sorry if duplicated.

Is it possible or recommended for business layer to using objects instead of ids?

SELECT c
FROM Child AS c
WHERE c.parent = :parent
public List<Child> list(final Parent parent) {

    // does parent must be managed?
    // how can I know that?
    // have parent even been persisted?

    return em.createNamedQuery(...).
        setParameter("parent", parent);
}

This is how I work with.

SELECT c
FROM Child AS c
WHERE c.parent.id = :parent_id
public List<Child> list(final Parent parent) {

    // wait! parent.id could be null!
    // it may haven't been persisted yet!

    return list(parent.getId());
}

public List<Child> list(final long parentId) {
    return em.createNamedQuery(...).
        setParameter("parent_id", parentId);
}

UPDATED QUESTION ————————————–

Do any JAX-RS or JAX-WS classes which each can be injected with @EJB can be said in the same JTA?

Here come the very original problem that I always curious about.

Let’s say we have two EJBs.

@Stateless
class ParentBean {

    public Parent find(...) {
    }
}

@Stateless
class ChildBean {

    public List<Child> list(final Parent parent) {
    }

    public List<Child> list(final long parentId) {
    }
}

What is a proper way to do with any EJB clients?

@Stateless // <<-- This is mandatory for being injected with @EJB, right?
@Path("/parents/{parent_id: \\d+}/children")
class ChildsResource {

    @GET
    @Path
    public Response list(@PathParam("parent_id") final long parentId) {

        // do i just have to stick to this approach?
        final List<Child> children1 = childBean.list(parentId);

        // is this parent managed?
        // is it ok to pass to other EJB?
        final Parent parent = parentBean.find(parentId);

        // is this gonna work?
        final List<Child> children2 = childBean.list(parent);

        ...
    }

    @EJB
    private ParentBean parentBean;

    @EJB
    private ChildBean childBean;
}
  • 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-08T09:21:49+00:00Added an answer on June 8, 2026 at 9:21 am

    If parent has not been persisted yet, then the query won’t work, and executing it doesn’t make much sense. It’s your responsibility to avoid executing it if the parent hasn’t been persisted. But I would not make it a responsibility of the find method itself. Just make it clear in the documentation of the method that the parent passed as argument must have an ID, or at least be persistent. No need to make the sameverification as the entity manager.

    If it has been persisted, but the flush hasn’t happened yet, the entity manager must flush before executing the query, precisely to make the query find the children of the new parent.

    At least with Hibernate, you may execute the query with a detached parent. If the ID is there, the query will use it and execute the query.

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

Sidebar

Related Questions

Possible Duplicate: Explicitly assigning values to a 2D Array? sorry if this has been
Possible Duplicate: What is the use of a Dispatcher Object in WPF? Sorry to
Possible Duplicate: Suggest a method for auto-updating my C# program I'm sorry if this
Possible Duplicate: trailing return type using decltype with a variadic template function I'm getting
Possible Duplicate: it's a google weather api?how to parse such kind of data using
Possible Duplicate: Linq: What is the difference between Select and Where What's the difference
Possible Duplicate: Difference between single quotes and double quotes in Javascript Sorry guys, but
Possible Duplicate: how to call pin annotation on button click in iphone Sorry if
Possible Duplicate: How do I compare strings in Java? I'm sorry for this rather
Possible Duplicate: Is it possible to refresh a single UITableViewCell in a UITableView? Sorry

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.