mandragorasster / hibernate-generic-dao

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

Saving not working with proxy objects #49

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Try to save an hibernate proxy object not in the Session. Here is a test
case : 

    public void testUpdateProxy() throws HibernateException, SecurityException,
            NoSuchMethodException {
        initDB();
        Address address = papaA.getHome().getAddress();
        try {
            Serializable id = address.getId();

            // When working with 2 differents session, the session.contains(entity)
returns false
            // see in _exists(Object entity) in HibernateBaseDAO 
            SessionImplementor openSession = (SessionImplementor)
target.getSessionFactory().openSession();

            Address proxy = (Address) JavassistLazyInitializer.getProxy(
                    Address.class.getName(),
                    Address.class,
                    new Class[] { HibernateProxy.class },
                    Address.class.getMethod("getId"),
                    Address.class.getMethod("setId", Long.class),
                    new AnyType(Hibernate.LONG, Hibernate.SERIALIZABLE),
                    id,
                    openSession
            );

            target.saveOrUpdateIsNew(proxy);

            Address address2 = target.get(Address.class, id);

            assertEquals("update on the proxy should work ", proxy.getCity(),
                    address2.getCity());

        } catch (Exception e) {
            e.printStackTrace();
            fail(e.getMessage());
        }

    }

What is the expected output? What do you see instead?
The test should pass. 

WARN    2009-10-01 14:42:22.285 org.hibernate.hql.QuerySplitter.concreteQueries() 
        no persistent classes found for query class: select id from
test.trg.model.Address_$$_javassist_5 where id = :id 
org.hibernate.QueryParameterException: could not locate named parameter [id]
    at
org.hibernate.engine.query.ParameterMetadata.getNamedParameterDescriptor(Paramet
erMetadata.java:99)
    at
org.hibernate.engine.query.ParameterMetadata.getNamedParameterExpectedType(Param
eterMetadata.java:105)
    at
org.hibernate.impl.AbstractQueryImpl.determineType(AbstractQueryImpl.java:437)
    at
org.hibernate.impl.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:407)
    at com.trg.dao.hibernate.HibernateBaseDAO._exists(HibernateBaseDAO.java:634)
    at com.trg.dao.hibernate.HibernateBaseDAO._exists(HibernateBaseDAO.java:623)
    at
com.trg.dao.hibernate.HibernateBaseDAO._saveOrUpdateIsNew(HibernateBaseDAO.java:
163)
    at
test.trg.dao.hibernate.HibernateBaseDAOTester.saveOrUpdateIsNew(HibernateBaseDAO
Tester.java:165)

What version of the product are you using? On what operating system?
trg-dao 0.5.0

I join a patch that corrects the problem.

P.S. : how can we contribute to the code ?

Original issue reported on code.google.com by mathieu....@gmail.com on 1 Oct 2009 at 12:49

Attachments:

GoogleCodeExporter commented 8 years ago
This issue is related to
http://code.google.com/p/hibernate-generic-dao/issues/detail?id=34

Original comment by mathieu....@gmail.com on 1 Oct 2009 at 12:54

GoogleCodeExporter commented 8 years ago
Thank you Mathieu again for reporting this bug and for the patch.

Original comment by dwolvert on 2 Oct 2009 at 12:17

GoogleCodeExporter commented 8 years ago

Original comment by dwolvert on 2 Oct 2009 at 12:17

GoogleCodeExporter commented 8 years ago

Original comment by dwolvert on 3 Oct 2009 at 6:05

GoogleCodeExporter commented 8 years ago
Fixed for 0.5.1

Original comment by dwolvert on 14 Nov 2009 at 3:41