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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:29:41+00:00 2026-06-01T19:29:41+00:00

This is my UserDAO bean defined in spring context public class UserDAO{ public boolean

  • 0

This is my UserDAO bean defined in spring context

public class UserDAO{

  public boolean isUserAlreadyExists(User user){
     //some logic
  }

  public void createUser(User user){
     //logic to add user to database
  }

}

This is my spring service bean

@Component
@Transactional(readonly="true",propagation=Propation.SUPPORTD)
public class UserService{

   @Autowired
   UserDAO userDAO;

   public void createUser(User){
       if(!userDAO.isUserAlreadyExists(user)){
           userDAO.createUser(user);
       }
   }
}

should i call isUserAlreadyExists from within UserDAO.createUser like this

//UserDAO.java
public void createUser(User user){

  if(!isAlreadyUserExists(user)){
     //user adding to database
  }
}

OR

Above Service bean implementation is ok.

  • 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-01T19:29:42+00:00Added an answer on June 1, 2026 at 7:29 pm

    That logic seems like it should be in your service layer; as in the former example. Your createUser() function in the DAO should only have to worry about creating, or adding the user. Let the service layer worry about what to do if the User already exists.

    Good read.

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

Sidebar

Related Questions

I have the following class defined as a bean: @Repository(userDao) public class UserDao extends
from the app-context.xml: <bean id=userDao class=com.vaannila.dao.UserDAOImpl> <property name=sessionFactory ref=mySessionFactory/> </bean> <bean name=MyServiceT class=com.s.server.ServiceT> <property
This is essentially what I want to do: public abstract class Uniform<T> { public
My app-config.xml has a definition for my UserDao bean: <bean id=userDao class=com.blah.core.db.hibernate.UserDaoImpl> <property name=sessionFactory
I would like to use @Repository spring annotation to avoid adding bean in context.xml.
I got this exception. This is my code: ApplicationContext context = new ClassPathXmlApplicationContext(classpath*:/servlet-context.xml); UserDao
I have a abstract class User and 3 classes who extend from this class
This is a Spring Security question. In my application, I have a User entity
I'm trying to make this 2-player web game application using Spring MVC. I have
Exception in thread main java.lang.NullPointerException at com.hibernate.UserDAO.findAll(UserDAO.java:154) at test.main(test.java:12) I am getting this error

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.