Exemplo n.º 1
0
  @Test
  public void shouldRunHibernateLazyInitialization() throws Exception {
    LazyInitializer initializer = mock(LazyInitializer.class);

    SomeProxy proxy = new SomeProxy(initializer);
    proxy.name = "my name";
    proxy.aField = "abc";

    when(initializer.getPersistentClass()).thenReturn(Client.class);
    when(proxy.getHibernateLazyInitializer().getImplementation()).thenReturn(proxy);

    serialization.from(proxy).serialize();

    assertThat(result(), is("{\"client\":{\"aField\":\"abc\",\"name\":\"my name\"}}"));
  }
Exemplo n.º 2
0
  protected Class<?> getClass(ExtendedObjectOutput out, Object v) {
    Class<?> cls = v.getClass();

    if (v instanceof HibernateProxy) {
      LazyInitializer initializer = ((HibernateProxy) v).getHibernateLazyInitializer();

      String className =
          (initializer.isUninitialized()
              ? initializer.getEntityName()
              : initializer.getImplementation().getClass().getName());

      if (className != null && className.length() > 0) {
        try {
          cls = out.getReflection().loadClass(className);
        } catch (ClassNotFoundException e) {
          cls = initializer.getPersistentClass();
        }
      }
    }

    return cls;
  }