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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T16:45:29+00:00 2026-05-10T16:45:29+00:00

In JPA the Entities are nice annotated Plain Old Java Objects. But I have

  • 0

In JPA the Entities are nice annotated Plain Old Java Objects. But I have not found a good way to interact with them and the database.

In my current app, my basic design is always to have a sequence based id as primary key so I usually have to look up entities by other properties than PK.

And for each Entity I have a stateless EJB of

@Stateless public class MyEntApiBean implements MyEntApi {   @PersistenceContext(unitName = 'xxx') @Inject EntityManager entityManager; 

with query methods that all are some variation

/**  * @return A List of all MyEnts that have some property  * @param someProp some property  */ public List<MyEnt> getAllMyEntsFromProp(final String someProp) {      try {         final Query query = entityManager.createQuery('select me from MyEnt me where me.someProp = :someProp');         query.setParameter('someProp', someProp);         return query.getResultList();     } catch(final NoResultException nre) {         log.warn('No MyEnts found');     }     return new ArrayList<MyEnt>(); } 

So:

  1. I really hate having these methods in an EJB because they seem to belong with the entities themselves, and the EJB local interfaces annoy the crap out of me.

  2. I hate the duplication that I have in each method with ‘try, createQuery, getResultList,catch, log, return’ (mostly a consequence of no closures or ‘with statement’ or somesuch in Java).

Does anyone have a suggestion for a better way to interact with the Entities and Database that addresses one or both of my issues?

I am currently thinking of doing some base methods with generics and reflection to get some generic query methods to reduce the duplication (issue 2) (I will put a prototype up for review later).

Thanks, Anders

  • 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. 2026-05-10T16:45:30+00:00Added an answer on May 10, 2026 at 4:45 pm

    Try Seam. The Query Objects do most of the work for you, and they’re easily extendable. Or, you could always implement a similar pattern.

    In general, Seam does a lot of useful stuff to bridge the gap between JPA and you view and business layers. You don’t have to use JSF for Seam to be useful.

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

Sidebar

Ask A Question

Stats

  • Questions 144k
  • Answers 144k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try to remove the AncestorLevel property, it's error prone and… May 12, 2026 at 8:42 am
  • Editorial Team
    Editorial Team added an answer If Gtk can't convince the window manager you can always… May 12, 2026 at 8:42 am
  • Editorial Team
    Editorial Team added an answer App Server. You see Tomcat as heavy in terms of… May 12, 2026 at 8:42 am

Related Questions

I have a SEAM app with some JPA/Hibernate entities. And I now wonder where
I am currently working on 100+ Java Objects created by someone with no JPA/Hibernate
An application that has been working well for months has stopped picking up the
Let's share Java based web application architectures! There are lots of different architectures for

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.