Пример #1
0
 /** {@inheritDoc} */
 @SuppressWarnings("unchecked")
 public boolean exists(PK id) {
   Session sess = getSession();
   IdentifierLoadAccess byId = sess.byId(persistentClass);
   T entity = (T) byId.load(id);
   return entity != null;
 }
Пример #2
0
  @Test
  public void testMultiLoadClearsBatchFetchQueue() {
    final EntityKey entityKey =
        new EntityKey(1, sessionFactory().getEntityPersister(SimpleEntity.class.getName()));

    Session session = openSession();
    session.getTransaction().begin();
    // create a proxy, which should add an entry to the BatchFetchQueue
    SimpleEntity first = session.byId(SimpleEntity.class).getReference(1);
    assertTrue(
        ((SessionImplementor) session)
            .getPersistenceContext()
            .getBatchFetchQueue()
            .containsEntityKey(entityKey));

    // now bulk load, which should clean up the BatchFetchQueue entry
    List<SimpleEntity> list =
        session.byMultipleIds(SimpleEntity.class).enableSessionCheck(true).multiLoad(ids(56));

    assertEquals(56, list.size());
    assertFalse(
        ((SessionImplementor) session)
            .getPersistenceContext()
            .getBatchFetchQueue()
            .containsEntityKey(entityKey));

    session.getTransaction().commit();
    session.close();
  }
  @Test
  public void testOneToOne() {
    Session session = SessionManager.openSession();
    Transaction tx = session.beginTransaction();
    Customer5 customer5 = new Customer5();
    customer5.setName("Absalom");
    session.persist(customer5);

    Address5 address5 = new Address5();
    address5.setAddress("100 Hebron Way");
    address5.setCity("Tel Aviv");

    address5.setCustomer(customer5);
    customer5.setAddress5(address5);

    tx.commit();
    session.close();

    session = SessionManager.openSession();
    tx = session.beginTransaction();
    Customer5 customer = (Customer5) session.byId(Customer5.class).load(customer5.getId());
    Hibernate.initialize(customer.getAddress5());
    tx.commit();
    session.close();

    assertEquals(customer.getName(), customer5.getName());
    assertEquals(customer.getAddress5().getAddress(), customer5.getAddress5().getAddress());
  }
  /** {@inheritDoc} */
  public Object get(Class clazz, Serializable id) {
    Session sess = getSession();
    IdentifierLoadAccess byId = sess.byId(clazz);
    Object entity = byId.load(id);

    if (entity == null) {
      log.warn("Uh oh, '" + clazz + "' object with id '" + id + "' not found...");
      throw new ObjectRetrievalFailureException(clazz, id);
    }

    return entity;
  }
Пример #5
0
  /** {@inheritDoc} */
  @SuppressWarnings("unchecked")
  public T get(PK id) {
    Session sess = getSession();
    IdentifierLoadAccess byId = sess.byId(persistentClass);
    T entity = (T) byId.load(id);

    if (entity == null) {
      log.warn("Uh oh, '" + this.persistentClass + "' object with id '" + id + "' not found...");
      throw new ObjectRetrievalFailureException(this.persistentClass, id);
    }

    return entity;
  }
Пример #6
0
 @Test
 public void testBasicMultiLoadWithManagedAndNoChecking() {
   Session session = openSession();
   session.getTransaction().begin();
   SimpleEntity first = session.byId(SimpleEntity.class).load(1);
   List<SimpleEntity> list = session.byMultipleIds(SimpleEntity.class).multiLoad(ids(56));
   assertEquals(56, list.size());
   // this check is HIGHLY specific to implementation in the batch loader
   // which puts existing managed entities first...
   assertSame(first, list.get(0));
   session.getTransaction().commit();
   session.close();
 }
Пример #7
0
 /** {@inheritDoc} */
 public void remove(PK id) {
   Session sess = getSession();
   IdentifierLoadAccess byId = sess.byId(persistentClass);
   T entity = (T) byId.load(id);
   sess.delete(entity);
 }
 /** {@inheritDoc} */
 public boolean exists(Class clazz, Serializable id) {
   Session sess = getSession();
   IdentifierLoadAccess byId = sess.byId(clazz);
   Object entity = byId.load(id);
   return entity != null;
 }
 /** {@inheritDoc} */
 public void remove(Class clazz, Serializable id) {
   Session sess = getSession();
   IdentifierLoadAccess byId = sess.byId(clazz);
   sess.delete(byId.load(id));
 }