user_vs
user_vs

Reputation: 1043

what should be the correct format of using anotation @repository in DAO layer?

is it like @Repository or @Repository("DAOname") ?

which is appropriate? why?

and

one major doubt regarding update and delete method in DAO layer! Is it safe to have logics in DAO layer?

i mean, for eg: DAO layer

@Transactional
public void deleteMethod(List list)
  {
  for(list)
  {
    deleteNamedQuery(list);
  }
}

Upvotes: 2

Views: 74

Answers (2)

user_vs
user_vs

Reputation: 1043

Service Layer(put the Iterating logic in service )

@Override
    public void deleteCheckedItems(List<Integer> selectdIdForDeletion, String userid) {
        try
        {
            for(Integer id:selectdIdForDeletion)
            {
                dao.deleteMethod(id, userid);  // called DAO method for delete
            }
        }catch(Exception e)
        {
            logger.info(e);
        }

    }

DAO Layer(removed the iterating delete logic )

@Transactional
public void deleteMethod(String id,String userid)
  {

    deleteNamedQuery(id,userid);

}

Upvotes: 0

Xstian
Xstian

Reputation: 8282

@Repository
public class UserDAO {}

in this case the bean if you perform a <context:component-scan base-package="your.package" /> will be named "userDAO"

@Repository("userRepository")
public class UserDAO {}

instead in this case will be named "userRepository". In few words are appropriate both solution, depends how you use it.

I suggest you not to add business logic within your DAO to maintain the Separation of Concern. See this link, in addition

A data access object (DAO) is an object that provides an abstract interface to some type of database or other persistence mechanism.

See this link

Upvotes: 3

Related Questions