shabeesh / generic-dao

Automatically exported from code.google.com/p/generic-dao
0 stars 0 forks source link

GenericDao don't insert #4

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I have:

My DAO Interface:

{{{
public interface UserDao extends IDao<User, Long> {

    void persist(User user);

    User findByLogin(String login);

}
}}}

My DAO Implementation:

{{{
@Repository
@Transactional(readOnly = true)
public class UserDaoImpl extends GenericDao<User, Long> implements UserDao {

    public UserDaoImpl() {
    }

    @SuppressWarnings("unchecked")
    public User findByLogin(String login) {
        List<User> list = findByCriteria(Criteria.forClass(User.class).add(
                Restrictions.eq("login", login)));

        if (list == null || list.size() != 1) {
            return null;
        }

        return list.get(0);

    }
}

}}}

But when i need save in the controller with: userDao.save(user) nothings
happen in the database.

I have using Spring + Spirng MVC + JPA + Hibernate

I need help, thanks you.

Please provide any additional information below.

Original issue reported on code.google.com by ccha...@gmail.com on 11 Sep 2009 at 5:10

GoogleCodeExporter commented 8 years ago
I think that your problem is that UserDaoImpl must be a EJB. I don't know if 
Spring
can work with PersistenceContext.
In my case, i work with JBoss Application Server, and same code as you write 
works fine.

Original comment by edson.go...@gmail.com on 11 Sep 2009 at 5:55

GoogleCodeExporter commented 8 years ago
I'm using tomcat, can this to be the problem?

Original comment by ccha...@gmail.com on 11 Sep 2009 at 6:11

GoogleCodeExporter commented 8 years ago
where is you void persist(User user) implementation ?

Original comment by matiasbe...@gmail.com on 11 Sep 2009 at 8:07

GoogleCodeExporter commented 8 years ago
to in no place, because he thought he could use the Save method of the parent 
class:

userDao.save(user);

Original comment by ccha...@gmail.com on 11 Sep 2009 at 8:09

GoogleCodeExporter commented 8 years ago
Really, i don't know.

I think that Spring should properly inject the persistence unit, regardless of 
the
container. But, as I use the JBoss application server simply can not tell you 
the
result of using Tomcat. 

I honestly do not know if I can help you much, since you are using a different
environment which I have running.

Original comment by edson.go...@gmail.com on 11 Sep 2009 at 11:49

GoogleCodeExporter commented 8 years ago
The fact is that you must continue to find out about the injection of the 
persistence
unit, poorly engineered design may be affecting the dependency injection.

Original comment by edson.go...@gmail.com on 11 Sep 2009 at 11:50

GoogleCodeExporter commented 8 years ago
ok thanks, I will continue looking and I can say

Original comment by ccha...@gmail.com on 12 Sep 2009 at 1:27