Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saving not working with proxy objects #49

Closed
GoogleCodeExporter opened this issue Mar 15, 2015 · 5 comments
Closed

Saving not working with proxy objects #49

GoogleCodeExporter opened this issue Mar 15, 2015 · 5 comments

Comments

@GoogleCodeExporter
Copy link

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
Copy link
Author

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
Copy link
Author

Thank you Mathieu again for reporting this bug and for the patch.

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

  • Changed state: Accepted

@GoogleCodeExporter
Copy link
Author

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

  • Added labels: Milestone-Release0.5.1

@GoogleCodeExporter
Copy link
Author

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

  • Changed state: Started

@GoogleCodeExporter
Copy link
Author

Fixed for 0.5.1

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

  • Changed state: Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant