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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:26:24+00:00 2026-05-15T03:26:24+00:00

I am writing an application that’s sole purpose in life is to do CRUD

  • 0

I am writing an application that’s sole purpose in life is to do CRUD operations for maintaining records in database. There are relationships between some of the tables/entities. Most examples I’ve seen for creating session beans deals with complex business logic/operations that interact with many entities which I don’t have.

Since my application is so very basic, what would be the best design for the session bean(s)?

I was thinking of having one session bean per entity which had CRUD the methods defined. Then I thought of combining all of those session beans into a single session bean. And then I found this blog entry which is intriguing, but I must admit I don’t understand all of it (what is a ServiceFacade?).

I’m leaning towards session bean/entity class, but would like to hear more experienced opinions.

Thanks.


Oops, here’s the blog link: http://www.adam-bien.com/roller/abien/entry/generic_crud_service_aka_dao

  • 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-15T03:26:25+00:00Added an answer on May 15, 2026 at 3:26 am

    Not sure what blog entry you’re talking about 🙂 But in your particular situation1, I’d probably use a single session bean implementing an interface similar to:

    public interface GenericCrudService {
        public <T> T create(T t);
        public <T> T find(Class<T> type, Object id);
        public <T> void delete(T t);
        public <T> T update(T t);
        public List findWithNamedQuery(String queryName);
        public List findWithNamedQuery(String queryName, int resultLimit);
        public List findWithNamedQuery(String namedQueryName, 
                                       Map<String, Object> parameters);
        public List findWithNamedQuery(String namedQueryName, 
                                       Map<String, Object> parameters,
                                       int resultLimit);
        public <T> List<T> findWithNativeQuery(String sql, Class<T> type);
    }
    

    And the bean would be as follow:

    @Stateless
    @Remote(GenericCrudService.class)
    @TransactionAttribute(TransactionAttributeType.MANDATORY)
    public class GenericCrudServiceBean implements GenericCrudService {
        @PersistenceContext
        private EntityManager em;
    
        @Override
        public <T> T create(T t) {
            em.persist(t);
            return t;
        }
    
        @Override
        public <T> T find(Class<T> type, Object id) {
            return em.find(type, id);
        }
    
        @Override
        public <T> void delete(T t) {
            t = em.merge(t);
            em.remove(t);
        }
    
        @Override
        public <T> T update(T t) {
            return em.merge(t);
        }
    
        @Override
        public List findWithNamedQuery(String queryName) {
            return em.createNamedQuery(queryName).getResultList();
        }
    
        @Override
        public List findWithNamedQuery(String queryName, int resultLimit) {
            return em.createNamedQuery(queryName).setMaxResults(resultLimit)
                    .getResultList();
        }
    
        @Override
        public List findWithNamedQuery(String namedQueryName,
                                       Map<String, Object> parameters) {
            return findWithNamedQuery(namedQueryName, parameters, 0);          
        }
    
        @Override
        public List findWithNamedQuery(String namedQueryName,
                                       Map<String, Object> parameters,
                                       int resultLimit) {
            Query query = this.em.createNamedQuery(namedQueryName);
            if(resultLimit > 0) {
                query.setMaxResults(resultLimit);            
            }
            for (Map.Entry<String, Object> entry : parameters.entrySet()) {
                query.setParameter(entry.getKey(), entry.getValue());
            }
            return query.getResultList();
        }
    
        @Override
        @SuppressWarnings("unchecked")
        public <T>  List<T> findWithNativeQuery(String sql, Class<T> type) {
            return em.createNativeQuery(sql, type).getResultList();
        }
    }
    

    See also

    • Generic CRUD Components with Java EE 5
    • Don’t repeat the DAO! – Build a generic typesafe DAO with Hibernate and Spring DAO

    1 Most application shouldn’t expose raw CRUD directly to clients but shield CRUD behind services implementing business rules and encapsulating access to Domain Stores (the EntityManager).

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

Sidebar

Related Questions

I am writing an application that shows Japanese Traditional Time (JTT for short). There
I am writing an application that records audio. I am looking into the feasibility
I'm writing an application that needs to perform some tasks only if there is
I am writing an application that will move data from one database to another
Im writing an application that updates a database that ive created. The application has
I'm writing an application that uses Hector to access a Cassandra database. I have
I am currently writing an application that will serve a similar purpose for multiple
While writing an application that interacts with a database the only way I can
Im writing an application that supposed to send coordinates in an SMS, but I've
I am writing an application that allows a user to place images on a

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.