4 Replies Latest reply on Aug 14, 2012 3:47 PM by lukas lukasz

    Springmvc , problem with generics dao

    lukas lukasz Newbie

      Hello i have got wery big problem and plz help me it is first time when junit test its fine but if i use function in real program its not working (none errors)

       

      i create very simple GenericsDAO like that:

       

      public abstract class GenericDAO <T , PK extends Serializable> implements IGenericDAO<T, PK>
      {
          
          @Autowired
          protected EntityManager entityManager;
      
          protected Class<T> clazz;
          
          public GenericDAO(final Class<T> clazz)
          {
              this.clazz = clazz;
          }
          
          @Override
          public void save(final T entity)
          {
              entityManager.persist(entity);
          }
          
          @Override
          public void delete(final T entity)
          {
              entityManager.remove(entity);
          }
      }
      

       

      It is very very simple generics dao as you see its one constructor with 1 attribute , next class must overwrite ...

       

      and i use standard simple example with member standard quickstart project in jboss

       

       

      @Repository
      @Transactional
      public class MemberDaoImpl extends GenericDAO<Member, Long> implements MemberDao
      {
          
          //default constructor start when object created
          public MemberDaoImpl() {
              super(Member.class);
          }
      
        //register first function persist
          @Override
          public void register(Member member)
          {
              entityManager.persist(member);
              return;
          }
      

       

      as you see this class have got 1 default constructor and initialize superclass with element Memver.class

       

      And its very strange because my junit like that :

       

       

         
          //memberDao.register(member);
          //used method with generics save the same function as resister
          memberDao.save(member);

       

      working fine but if i try use this function save in MemberController :

       

       

        @RequestMapping(method=RequestMethod.POST)
          public String registerNewMember(@Valid @ModelAttribute("newMember") Member newMember, BindingResult result, Model model)
          {
              if (!result.hasErrors()) {
                  
                  //memberDao.register(newMember);
                  //we used generics method save 
                  memberDao.save(newMember);
                  //save is no working why ???
      

       

      Its not working why ??

      plz its very interesting for me because its first time when i used junit and everything is fine byt if i try use function in real app its problem :/

       

      additional info ;

      i used Jboss as 7.1 Thunder

       

      I attach very very simple project quickstart spring mvc with aditional generics dao and new test plz told me what is wrong , :/ i havent got any idea i spend 2 days and dont know :/...