It looks to me that´s some problem with context loading only for testcases. 
I´m able to do CRUD operations using ControlePeso normally if I use the
container (mvn jetty:run) . So, how does the context is loading for
testcases in appfuse? 

Follows the routine I have created to add a new ControlePeso and it works
normally using the jetty container(save method from ControlePeso class).

        Authentication auth =
SecurityContextHolder.getContext().getAuthentication();
        User user = null;
        if (auth != null && auth.getPrincipal() instanceof UserDetails) 
            user = (User) auth.getPrincipal();

        
        controlePeso.setUser(user);
        
        controlePesoManager.save(controlePeso); 

So I really believe there´s some problem with context loading while
executing the test cases... Any ideas?? 

tx in advance..




mmaia wrote:
> 
> Yes, it is. Just forgot to mention here. 
> This errror is REALLY driving me mad, as I don´t have a clue about what´s
> causing the problem. Everything looks correct. 
> Any ideas? Please... :confused: :-(
> 
> 
> mraible wrote:
>> 
>> Did you make sure your class is mapped in hibernate.cfg.xml?
>> 
>> Matt
>> 
>> On Tue, Oct 7, 2008 at 9:08 AM, mmaia <[EMAIL PROTECTED]> wrote:
>> 
>>> Hi,
>>> I have added a simple relation from User to ControlePeso class, it´s a
>>> one
>>> to Many relationship.
>>> *In User class:*
>>>
>>>  private List controlePeso = new ArrayList();
>>> @OneToMany(cascade=CascadeType.ALL, mappedBy="user")
>>> public List getControlePeso()
>>> {
>>> return controlePeso;
>>> }
>>>
>>>
>>> *In ControlePeso class:*
>>>  @Entity
>>> @Table(name="controle_peso")
>>> public class ControlePeso extends BaseObject implements Serializable{
>>> ....
>>> private User user;
>>> @ManyToOne(optional=false)
>>> @JoinColumn(name="user_id", updatable=false, nullable=false)
>>> public User getUser()
>>> {
>>> return user;
>>> }
>>>
>>> I have used appfuse:gen with -Damp.genericCore=false option. Then I
>>> check
>>> and all classes have been generated for ControlePeso(Manager, DAO, etc)
>>>
>>> I hava also checked and found the entry added by appfuse:gen in
>>> applicationContext.xml for ControlePesoDaoHibernate and
>>> ControlePesoManger
>>>
>>> Then I have added a new entry in applicationContext-dao.xml for
>>> ControlePesoDaoHibernate.
>>>
>>> *I than changed the ControlePesoDaoTest class to test a new method I
>>> want
>>> to add to this*(I´ve changed the sample-data.xml to get this results
>>> ok!!!):
>>>
>>>  public void testGetTodosDoUsuario(int idUser)
>>> {
>>> List lista = new ArrayList();
>>> lista = controlePesoDao.getTodosDoUsuario(-1);
>>> assertEquals(3, lista.size());
>>> lista = controlePesoDao.getTodosDoUsuario(-2);
>>> assertEquals(1, lista.size());
>>> }
>>>
>>> *Finally I have added a new method in ControlePesoDao:*
>>>
>>>  public List getTodosDoUsuario(int idUser);
>>> and ControlePesoDaoHibernate:
>>>  public List getTodosDoUsuario(int idUser) {
>>> List controlePesoList = getHibernateTemplate().find("from ControlePeso
>>> where user.id=?", idUser);
>>> return controlePesoList;
>>> }
>>>  *After all this, when I try to run the dao layer test using:*
>>>
>>>  mvn test -Dtest=*DaoTest
>>> *I get the following error(taken from surefire reports):*
>>>
>>> [D:\workspaces\projetos\controlepeso\target\test-classes\WEB-INF\applicationContext.xml]:
>>> Cannot resolve reference to bean 'sessionFactory' while setting bean
>>> property 'sessionFactory'; nested exception is
>>> org.springframework.beans.factory.BeanCreationException: Error creating
>>> bean
>>> with name 'sessionFactory' defined in class path resource
>>> [applicationContext-dao.xml]: Invocation of init method failed; nested
>>> exception is org.hibernate.AnnotationException: Use of @OneToMany or
>>> @ManyToMany targeting an unmapped class:
>>> br.com.maweb.controlepeso.model.User.controlePeso[br.com.maweb.controlepeso.model.ControlePeso]
>>>
>>>
>>> I´m stuck on this for a couple of hours now and have no clue about
>>> what´s
>>> causing this. I´ve checked every place I could think of where the
>>> problem
>>> came, but no clue yet..
>>> Any ideas will be appreciate.
>>>
>>> tx in advance.
>>>
>>> P.S - I have uploaded the surefire report if you need a complete stack
>>> error.
>>> br.com.maweb.controlepeso.dao.UserDaoTest.txt<http://www.nabble.com/file/p19860344/br.com.maweb.controlepeso.dao.UserDaoTest.txt>
>>> ------------------------------
>>> View this message in context: OneToMany Relation Problem from
>>> User<http://www.nabble.com/OneToMany-Relation-Problem-from-User-tp19860344s2369p19860344.html>
>>> Sent from the AppFuse - User mailing list
>>> archive<http://www.nabble.com/AppFuse---User-f2370.html>at Nabble.com.
>>>
>> 
>> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/OneToMany-Relation-Problem-from-User-tp19860344s2369p19865277.html
Sent from the AppFuse - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to