Example usage for org.hibernate.type AnyType AnyType

List of usage examples for org.hibernate.type AnyType AnyType

Introduction

In this page you can find the example usage for org.hibernate.type AnyType AnyType.

Prototype

protected AnyType(Type discriminatorType, Type identifierType) 

Source Link

Document

Intended for use only from legacy ObjectType type definition

Usage

From source file:junit.googlecode.genericdao.dao.hibernate.BaseDAOTest.java

License:Apache License

@Test
public void testProxyIssues() throws HibernateException, SecurityException, NoSuchMethodException {
    initDB();//w w  w.  j ava 2 s .  c om
    Address address = papaA.getHome().getAddress();
    try {
        Serializable id = address.getId();

        // When working with 2 different session, the session.contains(entity) returns false
        // see in _exists(Object entity) in HibernateBaseDAO
        SessionImplementor openSession = (SessionImplementor) sessionFactory.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(StandardBasicTypes.LONG, StandardBasicTypes.SERIALIZABLE), id, openSession);

        // If this is not working properly, this will throw an error
        target.saveOrUpdateIsNew(proxy);

        //So will this
        Address address2 = target.get(proxy.getClass(), id);

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

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

}

From source file:junit.trg.dao.hibernate.BaseDAOTest.java

License:Apache License

public void testProxyIssues() throws HibernateException, SecurityException, NoSuchMethodException {
    initDB();/* w w w .j a  v a  2s  .  c om*/
    Address address = papaA.getHome().getAddress();
    try {
        Serializable id = address.getId();

        // When working with 2 different session, the session.contains(entity) returns false
        // see in _exists(Object entity) in HibernateBaseDAO
        SessionImplementor openSession = (SessionImplementor) sessionFactory.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);

        // If this is not working properly, this will throw an error
        target.saveOrUpdateIsNew(proxy);

        //So will this
        Address address2 = target.get(proxy.getClass(), id);

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

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

}