org.hibernate.Transaction.commit() - java examples

Here are the examples of the java api org.hibernate.Transaction.commit() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

155 Examples 7

18 View Complete Implementation : CollectionTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testMerge() throws HibernateException, SQLException {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    User u = new User("gavin");
    u.getPermissions().add(new Permission("obnoxiousness"));
    u.getPermissions().add(new Permission("pigheadedness"));
    s.persist(u);
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    User u2 = (User) s.createCriteria(User.clreplaced).uniqueResult();
    // forces one shot delete
    u2.setPermissions(null);
    s.merge(u);
    t.commit();
    s.close();
    u.getPermissions().add(new Permission("silliness"));
    s = openSession();
    t = s.beginTransaction();
    s.merge(u);
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    u2 = (User) s.createCriteria(User.clreplaced).uniqueResult();
    replacedertEquals(u2.getPermissions().size(), 3);
    replacedertEquals(((Permission) u2.getPermissions().get(0)).getType(), "obnoxiousness");
    replacedertEquals(((Permission) u2.getPermissions().get(2)).getType(), "silliness");
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    s.delete(u2);
    s.flush();
    t.commit();
    s.close();
}

18 View Complete Implementation : MapElementFormulaTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testManyToManyFormula() {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    User gavin = new User("gavin", "secret");
    User turin = new User("turin", "tiger");
    Group g = new Group("users");
    g.getUsers().put("Gavin", gavin);
    g.getUsers().put("Turin", turin);
    s.persist(g);
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    g = (Group) s.get(Group.clreplaced, "users");
    replacedertEquals(g.getUsers().size(), 2);
    g.getUsers().remove("Turin");
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    g = (Group) s.get(Group.clreplaced, "users");
    replacedertEquals(g.getUsers().size(), 1);
    s.delete(g);
    s.delete(g.getUsers().get("Gavin"));
    s.delete(s.get(User.clreplaced, "turin"));
    t.commit();
    s.close();
}

18 View Complete Implementation : InterceptorTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testPropertyIntercept() {
    Session s = openSession(new PropertyInterceptor());
    Transaction t = s.beginTransaction();
    User u = new User("Gavin", "nivag");
    s.persist(u);
    u.setPreplacedword("vagni");
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    u = (User) s.get(User.clreplaced, "Gavin");
    replacedertNotNull(u.getCreated());
    replacedertNotNull(u.getLastUpdated());
    s.delete(u);
    t.commit();
    s.close();
}

18 View Complete Implementation : CollectionTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testExtraLazy() throws HibernateException, SQLException {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    User u = new User("gavin");
    u.getPermissions().add(new Permission("obnoxiousness"));
    u.getPermissions().add(new Permission("pigheadedness"));
    u.getSessionData().put("foo", "foo value");
    s.persist(u);
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    u = (User) s.get(User.clreplaced, "gavin");
    replacedertFalse(Hibernate.isInitialized(u.getPermissions()));
    replacedertEquals(u.getPermissions().size(), 2);
    replacedertTrue(u.getPermissions().contains(new Permission("obnoxiousness")));
    replacedertFalse(u.getPermissions().contains(new Permission("silliness")));
    replacedertNotNull(u.getPermissions().get(1));
    replacedertNull(u.getPermissions().get(3));
    replacedertFalse(Hibernate.isInitialized(u.getPermissions()));
    replacedertFalse(Hibernate.isInitialized(u.getSessionData()));
    replacedertEquals(u.getSessionData().size(), 1);
    replacedertTrue(u.getSessionData().containsKey("foo"));
    replacedertFalse(u.getSessionData().containsKey("bar"));
    replacedertTrue(u.getSessionData().containsValue("foo value"));
    replacedertFalse(u.getSessionData().containsValue("bar"));
    replacedertEquals("foo value", u.getSessionData().get("foo"));
    replacedertNull(u.getSessionData().get("bar"));
    replacedertFalse(Hibernate.isInitialized(u.getSessionData()));
    replacedertFalse(Hibernate.isInitialized(u.getSessionData()));
    u.getSessionData().put("bar", "bar value");
    u.getSessionAttributeNames().add("bar");
    replacedertFalse(Hibernate.isInitialized(u.getSessionAttributeNames()));
    replacedertTrue(Hibernate.isInitialized(u.getSessionData()));
    s.delete(u);
    t.commit();
    s.close();
}

18 View Complete Implementation : UnconstrainedTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testUnconstrainedOuterJoinFetch() {
    Session session = openSession();
    Transaction tx = session.beginTransaction();
    Person p = new Person("gavin");
    p.setEmployeeId("123456");
    session.persist(p);
    tx.commit();
    session.close();
    getSessions().evict(Person.clreplaced);
    session = openSession();
    tx = session.beginTransaction();
    p = (Person) session.createCriteria(Person.clreplaced).setFetchMode("employee", FetchMode.JOIN).add(Restrictions.idEq("gavin")).uniqueResult();
    replacedertNull(p.getEmployee());
    p.setEmployee(new Employee("123456"));
    tx.commit();
    session.close();
    getSessions().evict(Person.clreplaced);
    session = openSession();
    tx = session.beginTransaction();
    p = (Person) session.createCriteria(Person.clreplaced).setFetchMode("employee", FetchMode.JOIN).add(Restrictions.idEq("gavin")).uniqueResult();
    replacedertTrue(Hibernate.isInitialized(p.getEmployee()));
    replacedertNotNull(p.getEmployee());
    session.delete(p);
    tx.commit();
    session.close();
}

18 View Complete Implementation : SubclassPropertyRefTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testOneToOnePropertyRef() {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    Customer c = new Customer();
    c.setName("Emmanuel");
    c.setCustomerId("C123-456");
    c.setPersonId("P123-456");
    Account a = new Account();
    a.setCustomer(c);
    a.setPerson(c);
    a.setType('X');
    s.persist(c);
    s.persist(a);
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    a = (Account) s.createQuery("from Account acc join fetch acc.customer join fetch acc.person").uniqueResult();
    replacedertNotNull(a.getCustomer());
    replacedertTrue(Hibernate.isInitialized(a.getCustomer()));
    replacedertNotNull(a.getPerson());
    replacedertTrue(Hibernate.isInitialized(a.getPerson()));
    c = (Customer) s.createQuery("from Customer").uniqueResult();
    replacedertSame(c, a.getCustomer());
    replacedertSame(c, a.getPerson());
    s.delete(a);
    s.delete(a.getCustomer());
    s.delete(a.getPerson());
    t.commit();
    s.close();
}

18 View Complete Implementation : JoinedSubclassPropertyRefTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testPropertyRefToJoinedSubclreplaced() {
    Session session = openSession();
    Transaction tx = session.beginTransaction();
    Person p = new Person();
    p.setName("Gavin King");
    BankAccount acc = new BankAccount();
    acc.setBsb("0634");
    acc.setType('B');
    acc.setAccountNumber("xxx-123-abc");
    p.setBankAccount(acc);
    session.persist(p);
    tx.commit();
    session.close();
    session = openSession();
    tx = session.beginTransaction();
    p = (Person) session.get(Person.clreplaced, p.getId());
    replacedertNotNull(p.getBankAccount());
    replacedertTrue(Hibernate.isInitialized(p.getBankAccount()));
    tx.commit();
    session.close();
    session = openSession();
    tx = session.beginTransaction();
    p = (Person) session.createCriteria(Person.clreplaced).setFetchMode("bankAccount", FetchMode.JOIN).uniqueResult();
    replacedertNotNull(p.getBankAccount());
    replacedertTrue(Hibernate.isInitialized(p.getBankAccount()));
    tx.commit();
    session.close();
    session = openSession();
    tx = session.beginTransaction();
    session.delete(p);
    tx.commit();
    session.close();
}

18 View Complete Implementation : PaginationTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testPagination() {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    for (int i = 0; i < 10; i++) {
        DataPoint dp = new DataPoint();
        dp.setX(new BigDecimal(i * 0.1d).setScale(19, BigDecimal.ROUND_DOWN));
        dp.setY(new BigDecimal(Math.cos(dp.getX().doubleValue())).setScale(19, BigDecimal.ROUND_DOWN));
        s.persist(dp);
    }
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    int size = s.createSQLQuery("select id, xval, yval, description from DataPoint order by xval, yval").addEnreplacedy(DataPoint.clreplaced).setMaxResults(5).list().size();
    replacedertEquals(size, 5);
    size = s.createQuery("from DataPoint order by x, y").setFirstResult(5).setMaxResults(2).list().size();
    replacedertEquals(size, 2);
    size = s.createCriteria(DataPoint.clreplaced).addOrder(Order.asc("x")).addOrder(Order.asc("y")).setFirstResult(8).list().size();
    replacedertEquals(size, 2);
    t.commit();
    s.close();
}

18 View Complete Implementation : InterceptorTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testCollectionIntercept() {
    Session s = openSession(new CollectionInterceptor());
    Transaction t = s.beginTransaction();
    User u = new User("Gavin", "nivag");
    s.persist(u);
    u.setPreplacedword("vagni");
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    u = (User) s.get(User.clreplaced, "Gavin");
    replacedertEquals(2, u.getActions().size());
    s.delete(u);
    t.commit();
    s.close();
}

18 View Complete Implementation : InstrumentCacheTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testInitFromCache() {
    Session s;
    Transaction tx;
    s = getSessions().openSession();
    tx = s.beginTransaction();
    s.persist(new Doreplacedent("HiA", "Hibernate book", "Hibernate is...."));
    tx.commit();
    s.close();
    s = getSessions().openSession();
    tx = s.beginTransaction();
    s.createQuery("from Doreplacedent fetch all properties").uniqueResult();
    tx.commit();
    s.close();
    getSessions().getStatistics().clear();
    s = getSessions().openSession();
    tx = s.beginTransaction();
    Doreplacedent d = (Doreplacedent) s.createCriteria(Doreplacedent.clreplaced).uniqueResult();
    replacedertFalse(Hibernate.isPropertyInitialized(d, "text"));
    replacedertFalse(Hibernate.isPropertyInitialized(d, "summary"));
    replacedertEquals("Hibernate is....", d.getText());
    replacedertTrue(Hibernate.isPropertyInitialized(d, "text"));
    replacedertTrue(Hibernate.isPropertyInitialized(d, "summary"));
    tx.commit();
    s.close();
    replacedertEquals(2, getSessions().getStatistics().getPrepareStatementCount());
    s = getSessions().openSession();
    tx = s.beginTransaction();
    d = (Doreplacedent) s.get(Doreplacedent.clreplaced, d.getId());
    replacedertFalse(Hibernate.isPropertyInitialized(d, "text"));
    replacedertFalse(Hibernate.isPropertyInitialized(d, "summary"));
    tx.commit();
    s.close();
}

18 View Complete Implementation : JPAProxyTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
/**
 * The ejb3 find() method maps to the Hibernate get() method
 */
public void testGetSemantics() {
    Long nonExistentId = new Long(-1);
    Session s = openSession();
    Transaction txn = s.beginTransaction();
    Item item = (Item) s.get(Item.clreplaced, nonExistentId);
    replacedertNull("get() of non-existent enreplacedy did not return null", item);
    txn.commit();
    s.close();
    s = openSession();
    txn = s.beginTransaction();
    // first load() it to generate a proxy...
    item = (Item) s.load(Item.clreplaced, nonExistentId);
    replacedertFalse(Hibernate.isInitialized(item));
    // then try to get() it to make sure we get an exception
    try {
        s.get(Item.clreplaced, nonExistentId);
        fail("force load did not fail on non-existent enreplacedy");
    } catch (EnreplacedyNotFoundException e) {
    // expected behavior
    } catch (replacedertionFailedError e) {
        throw e;
    } catch (Throwable t) {
        fail("unexpected exception type on non-existent enreplacedy force load : " + t);
    }
    txn.commit();
    s.close();
}

18 View Complete Implementation : OneToOneCacheTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
/**
 * loads the newly created MainObject
 * and adds a new Object2 to it
 * <p/>
 * one hibernate transaction
 */
private void addObject2() throws HibernateException {
    Session session = openSession();
    Transaction tx = session.beginTransaction();
    MainObject mo = (MainObject) session.load(MainObject.clreplaced, generatedId);
    Object2 toAdd = new Object2();
    toAdd.setDummy("test");
    // toAdd should now be saved by cascade
    mo.setObj2(toAdd);
    tx.commit();
    session.close();
}

18 View Complete Implementation : DbVersionTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testCollectionVersion() throws Exception {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    User steve = new User("steve");
    s.persist(steve);
    Group admin = new Group("admin");
    s.persist(admin);
    t.commit();
    s.close();
    Timestamp steveTimestamp = steve.getTimestamp();
    // For dialects (Oracle8 for example) which do not return "true
    // timestamps" sleep for a bit to allow the db date-time increment...
    Thread.sleep(1500);
    s = openSession();
    t = s.beginTransaction();
    steve = (User) s.get(User.clreplaced, steve.getId());
    admin = (Group) s.get(Group.clreplaced, admin.getId());
    steve.getGroups().add(admin);
    admin.getUsers().add(steve);
    t.commit();
    s.close();
    replacedertFalse("owner version not incremented", Hibernate.TIMESTAMP.isEqual(steveTimestamp, steve.getTimestamp()));
    steveTimestamp = steve.getTimestamp();
    Thread.sleep(1500);
    s = openSession();
    t = s.beginTransaction();
    steve = (User) s.get(User.clreplaced, steve.getId());
    steve.getGroups().clear();
    t.commit();
    s.close();
    replacedertFalse("owner version not incremented", Hibernate.TIMESTAMP.isEqual(steveTimestamp, steve.getTimestamp()));
    s = openSession();
    t = s.beginTransaction();
    s.delete(s.load(User.clreplaced, steve.getId()));
    s.delete(s.load(Group.clreplaced, admin.getId()));
    t.commit();
    s.close();
}

18 View Complete Implementation : CreateTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testCreateException() {
    Session s = openSession();
    Transaction tx = s.beginTransaction();
    Node dupe = new Node("dupe");
    s.persist(dupe);
    s.persist(dupe);
    tx.commit();
    s.close();
    s = openSession();
    tx = s.beginTransaction();
    s.persist(dupe);
    try {
        tx.commit();
        replacedertFalse(true);
    } catch (ConstraintViolationException cve) {
    // verify that an exception is thrown!
    }
    tx.rollback();
    s.close();
    Node nondupe = new Node("nondupe");
    nondupe.addChild(dupe);
    s = openSession();
    tx = s.beginTransaction();
    s.persist(nondupe);
    try {
        tx.commit();
        replacedertFalse(true);
    } catch (ConstraintViolationException cve) {
    // verify that an exception is thrown!
    }
    tx.rollback();
    s.close();
}

18 View Complete Implementation : CreateTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testNoUpdatesOnCreateVersionedWithCollection() {
    clearCounts();
    Session s = openSession();
    Transaction tx = s.beginTransaction();
    VersionedEnreplacedy root = new VersionedEnreplacedy("root", "root");
    VersionedEnreplacedy child = new VersionedEnreplacedy("c1", "child-1");
    root.getChildren().add(child);
    child.setParent(root);
    s.save(root);
    tx.commit();
    s.close();
    replacedertInsertCount(2);
    replacedertUpdateCount(0);
    replacedertDeleteCount(0);
    s = openSession();
    tx = s.beginTransaction();
    s.delete(root);
    tx.commit();
    s.close();
    replacedertUpdateCount(0);
    replacedertDeleteCount(2);
}

18 View Complete Implementation : ArrayTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testArrayJoinFetch() throws Exception {
    Session s;
    Transaction tx;
    s = openSession();
    tx = s.beginTransaction();
    A a = new A();
    B b = new B();
    a.setBs(new B[] { b });
    s.persist(a);
    tx.commit();
    s.close();
    s = openSession();
    tx = s.beginTransaction();
    a = (A) s.get(A.clreplaced, a.getId());
    replacedertNotNull(a);
    replacedertNotNull(a.getBs());
    replacedertEquals(a.getBs().length, 1);
    replacedertNotNull(a.getBs()[0]);
    s.delete(a);
    s.delete(a.getBs()[0]);
    tx.commit();
    s.close();
}

18 View Complete Implementation : ImmutableTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testImmutable() {
    Contract c = new Contract("gavin", "phone");
    ContractVariation cv1 = new ContractVariation(1, c);
    cv1.setText("expensive");
    ContractVariation cv2 = new ContractVariation(2, c);
    cv2.setText("more expensive");
    Session s = openSession();
    Transaction t = s.beginTransaction();
    s.persist(c);
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    c = (Contract) s.createCriteria(Contract.clreplaced).uniqueResult();
    c.setCustomerName("foo bar");
    c.getVariations().add(new ContractVariation(3, c));
    cv1 = (ContractVariation) c.getVariations().iterator().next();
    cv1.setText("blah blah");
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    c = (Contract) s.createCriteria(Contract.clreplaced).uniqueResult();
    replacedertEquals(c.getCustomerName(), "gavin");
    replacedertEquals(c.getVariations().size(), 2);
    cv1 = (ContractVariation) c.getVariations().iterator().next();
    replacedertEquals(cv1.getText(), "expensive");
    s.delete(c);
    replacedertEquals(s.createCriteria(Contract.clreplaced).setProjection(Projections.rowCount()).uniqueResult(), new Integer(0));
    replacedertEquals(s.createCriteria(ContractVariation.clreplaced).setProjection(Projections.rowCount()).uniqueResult(), new Integer(0));
    t.commit();
    s.close();
}

18 View Complete Implementation : AbstractComponentPropertyRefTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testPropertiesRefCascades() {
    Session session = openSession();
    Transaction trans = session.beginTransaction();
    ServerImpl server = new ServerImpl();
    session.save(server);
    AddressImpl address = new AddressImpl();
    server.setAddress(address);
    address.setServer(server);
    session.flush();
    session.createQuery("from Server s join fetch s.address").list();
    trans.commit();
    session.close();
    replacedertNotNull(server.getId());
    replacedertNotNull(address.getId());
    session = openSession();
    trans = session.beginTransaction();
    session.delete(address);
    session.delete(server);
    trans.commit();
    session.close();
}

18 View Complete Implementation : MultipleHiLoPerTableGeneratorTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testDistinctId() throws Exception {
    Session s = openSession();
    Transaction tx = s.beginTransaction();
    int testLength = 8;
    Car[] cars = new Car[testLength];
    Plane[] planes = new Plane[testLength];
    for (int i = 0; i < testLength; i++) {
        cars[i] = new Car();
        cars[i].setColor("Color" + i);
        planes[i] = new Plane();
        planes[i].setNbrOfSeats(i);
        s.persist(cars[i]);
    // s.persist(planes[i]);
    }
    tx.commit();
    s.close();
    for (int i = 0; i < testLength; i++) {
        replacedertEquals(i + 1, cars[i].getId().intValue());
    // replacedertEquals(i+1, planes[i].getId().intValue());
    }
    s = openSession();
    tx = s.beginTransaction();
    s.createQuery("delete from Car").executeUpdate();
    tx.commit();
    s.close();
}

18 View Complete Implementation : ParameterizedUserCollectionTypeTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testBasicOperation() {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    Enreplacedy enreplacedy = new Enreplacedy("tester");
    enreplacedy.getValues().add("value-1");
    s.persist(enreplacedy);
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    enreplacedy = (Enreplacedy) s.get(Enreplacedy.clreplaced, "tester");
    replacedertTrue(Hibernate.isInitialized(enreplacedy.getValues()));
    replacedertEquals(1, enreplacedy.getValues().size());
    replacedertEquals("Hello", ((DefaultableList) enreplacedy.getValues()).getDefaultValue());
    s.delete(enreplacedy);
    t.commit();
    s.close();
}

18 View Complete Implementation : CollectionTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testFetch() {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    User u = new User("gavin");
    u.getPermissions().add(new Permission("obnoxiousness"));
    u.getPermissions().add(new Permission("pigheadedness"));
    u.getEmailAddresses().add(new Email("[email protected]"));
    u.getEmailAddresses().add(new Email("[email protected]"));
    s.persist(u);
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    User u2 = (User) s.createCriteria(User.clreplaced).uniqueResult();
    replacedertTrue(Hibernate.isInitialized(u2.getEmailAddresses()));
    replacedertFalse(Hibernate.isInitialized(u2.getPermissions()));
    replacedertEquals(u2.getEmailAddresses().size(), 2);
    s.delete(u2);
    t.commit();
    s.close();
}

18 View Complete Implementation : FetchingTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testLazy() throws Exception {
    Session s;
    Transaction tx;
    s = openSession();
    tx = s.beginTransaction();
    Person p = new Person("Gavin", "King", "JBoss Inc");
    Stay stay = new Stay(p, new Date(), new Date(), "A380", "Blah", "Blah");
    p.addStay(stay);
    s.persist(p);
    tx.commit();
    s.clear();
    tx = s.beginTransaction();
    p = (Person) s.createQuery("select p from Person p where p.firstName = :name").setParameter("name", "Gavin").uniqueResult();
    replacedertFalse(Hibernate.isInitialized(p.getStays()));
    s.delete(p);
    tx.commit();
    s.close();
}

18 View Complete Implementation : RowIdTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testRowId() {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    Point p = new Point(new BigDecimal(1.0), new BigDecimal(1.0));
    s.persist(p);
    t.commit();
    s.clear();
    t = s.beginTransaction();
    p = (Point) s.createCriteria(Point.clreplaced).uniqueResult();
    p.setDescription("new desc");
    t.commit();
    s.clear();
    t = s.beginTransaction();
    p = (Point) s.createQuery("from Point").uniqueResult();
    p.setDescription("new new desc");
    t.commit();
    s.clear();
    t = s.beginTransaction();
    p = (Point) s.get(Point.clreplaced, p);
    p.setDescription("new new new desc");
    t.commit();
    s.close();
}

18 View Complete Implementation : CreateTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testBasic() throws Exception {
    Session s;
    Transaction tx;
    s = openSession();
    tx = s.beginTransaction();
    Employer er = new Employer();
    Employee ee = new Employee();
    s.persist(ee);
    Collection erColl = new ArrayList();
    Collection eeColl = new ArrayList();
    erColl.add(ee);
    eeColl.add(er);
    er.setEmployees(erColl);
    ee.setEmployers(eeColl);
    tx.commit();
    s.close();
    s = openSession();
    tx = s.beginTransaction();
    er = (Employer) s.load(Employer.clreplaced, er.getId());
    replacedertNotNull(er);
    replacedertNotNull(er.getEmployees());
    replacedertEquals(1, er.getEmployees().size());
    Employee eeFromDb = (Employee) er.getEmployees().iterator().next();
    replacedertEquals(ee.getId(), eeFromDb.getId());
    tx.commit();
    s.close();
}

18 View Complete Implementation : IdBagTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testJoin() throws HibernateException, SQLException {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    User gavin = new User("gavin");
    Group admins = new Group("admins");
    Group plebs = new Group("plebs");
    gavin.getGroups().add(plebs);
    gavin.getGroups().add(admins);
    s.persist(gavin);
    s.persist(plebs);
    s.persist(admins);
    List l = s.createQuery("from User u join u.groups g").list();
    replacedertEquals(l.size(), 2);
    s.clear();
    gavin = (User) s.createQuery("from User u join fetch u.groups").uniqueResult();
    replacedertTrue(Hibernate.isInitialized(gavin.getGroups()));
    replacedertEquals(gavin.getGroups().size(), 2);
    replacedertEquals(((Group) gavin.getGroups().get(0)).getName(), "admins");
    s.delete(gavin.getGroups().get(0));
    s.delete(gavin.getGroups().get(1));
    s.delete(gavin);
    t.commit();
    s.close();
}

18 View Complete Implementation : PropertyRefTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testDeleteParentWithBidirOrphanDeleteCollectionBasedOnPropertyRef() {
    Session session = openSession();
    Transaction txn = session.beginTransaction();
    User user = new User("test");
    user.addMail("test");
    user.addMail("test");
    session.save(user);
    txn.commit();
    session.close();
    session = openSession();
    txn = session.beginTransaction();
    user = (User) session.load(User.clreplaced, user.getId());
    session.delete(user);
    txn.commit();
    session.close();
    session = openSession();
    txn = session.beginTransaction();
    session.createQuery("delete from Mail where alias = :alias").setString("alias", "test").executeUpdate();
    session.createQuery("delete from User where userid = :userid").setString("userid", "test").executeUpdate();
    txn.commit();
    session.close();
}

18 View Complete Implementation : DeleteTransientEntityTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testTransientEnreplacedyDeletionCascadingToPersistentreplacedociation() {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    Address address = new Address();
    address.setInfo("123 Main St.");
    s.save(address);
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    address = (Address) s.get(Address.clreplaced, address.getId());
    Person p = new Person();
    p.getAddresses().add(address);
    s.delete(p);
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    Long count = (Long) s.createQuery("select count(*) from Address").list().get(0);
    replacedertEquals("delete not cascaded properly across transient enreplacedy", 0, count.longValue());
    t.commit();
    s.close();
}

18 View Complete Implementation : UnconstrainedTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testUnconstrainedNoCache() {
    Session session = openSession();
    Transaction tx = session.beginTransaction();
    Person p = new Person("gavin");
    p.setEmployeeId("123456");
    session.persist(p);
    tx.commit();
    session.close();
    getSessions().evict(Person.clreplaced);
    session = openSession();
    tx = session.beginTransaction();
    p = (Person) session.get(Person.clreplaced, "gavin");
    replacedertNull(p.getEmployee());
    p.setEmployee(new Employee("123456"));
    tx.commit();
    session.close();
    getSessions().evict(Person.clreplaced);
    session = openSession();
    tx = session.beginTransaction();
    p = (Person) session.get(Person.clreplaced, "gavin");
    replacedertTrue(Hibernate.isInitialized(p.getEmployee()));
    replacedertNotNull(p.getEmployee());
    session.delete(p);
    tx.commit();
    session.close();
}

18 View Complete Implementation : MapCompositeElementTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testQueryMapCompositeElement() {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    Part top = new Part("top", "The top part");
    Part bottom = new Part("bottom", "The bottom part");
    Product prod = new Product("Some Thing");
    prod.getParts().put("Top", top);
    prod.getParts().put("Bottom", bottom);
    s.persist(prod);
    Item item = new Item("123456", prod);
    s.persist(item);
    List list = s.createQuery("select new Part( part.name, part.description ) from Product prod join prod.parts part order by part.name desc").list();
    replacedertEquals(list.size(), 2);
    replacedertTrue(list.get(0) instanceof Part);
    replacedertTrue(list.get(1) instanceof Part);
    Part part = (Part) list.get(0);
    replacedertEquals(part.getName(), "top");
    replacedertEquals(part.getDescription(), "The top part");
    list = s.createQuery("select new Part( part.name, part.description ) from Product prod join prod.parts part where index(part) = 'Top'").list();
    replacedertEquals(list.size(), 1);
    replacedertTrue(list.get(0) instanceof Part);
    part = (Part) list.get(0);
    replacedertEquals(part.getName(), "top");
    replacedertEquals(part.getDescription(), "The top part");
    list = s.createQuery("from Product p where 'Top' in indices(p.parts)").list();
    replacedertEquals(list.size(), 1);
    replacedertSame(list.get(0), prod);
    list = s.createQuery("select i from Item i join i.product p where 'Top' in indices(p.parts)").list();
    replacedertEquals(list.size(), 1);
    replacedertSame(list.get(0), item);
    list = s.createQuery("from Item i where 'Top' in indices(i.product.parts)").list();
    replacedertEquals(list.size(), 1);
    replacedertSame(list.get(0), item);
    s.delete(item);
    s.delete(prod);
    t.commit();
    s.close();
}

18 View Complete Implementation : TimestampTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testUpdateFalse() {
    getSessions().getStatistics().clear();
    Session s = openSession();
    Transaction t = s.beginTransaction();
    User u = new User("gavin", "secret", new Person("Gavin King", new Date(), "Karbarook Ave"));
    s.persist(u);
    s.flush();
    u.getPerson().setName("XXXXYYYYY");
    t.commit();
    s.close();
    replacedertEquals(1, getSessions().getStatistics().getEnreplacedyInsertCount());
    replacedertEquals(0, getSessions().getStatistics().getEnreplacedyUpdateCount());
    s = openSession();
    t = s.beginTransaction();
    u = (User) s.get(User.clreplaced, "gavin");
    replacedertEquals(u.getPerson().getName(), "Gavin King");
    s.delete(u);
    t.commit();
    s.close();
    replacedertEquals(1, getSessions().getStatistics().getEnreplacedyDeleteCount());
}

18 View Complete Implementation : WithClauseTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testWithClause() {
    TestData data = new TestData();
    data.prepare();
    Session s = openSession();
    Transaction txn = s.beginTransaction();
    // one-to-many
    List list = s.createQuery("from Human h inner join h.offspring as o with o.bodyWeight < :someLimit").setDouble("someLimit", 1).list();
    replacedertTrue("ad-hoc on did not take effect", list.isEmpty());
    // many-to-one
    list = s.createQuery("from Animal a inner join a.mother as m with m.bodyWeight < :someLimit").setDouble("someLimit", 1).list();
    replacedertTrue("ad-hoc on did not take effect", list.isEmpty());
    // many-to-many
    list = s.createQuery("from Human h inner join h.friends as f with f.nickName like 'bubba'").list();
    replacedertTrue("ad-hoc on did not take effect", list.isEmpty());
    txn.commit();
    s.close();
    data.cleanup();
}

18 View Complete Implementation : CreateTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testCreateTreeWithGeneratedId() {
    clearCounts();
    Session s = openSession();
    Transaction tx = s.beginTransaction();
    NumberedNode root = new NumberedNode("root");
    NumberedNode child = new NumberedNode("child");
    root.addChild(child);
    s.persist(root);
    tx.commit();
    s.close();
    replacedertInsertCount(2);
    replacedertUpdateCount(0);
    s = openSession();
    tx = s.beginTransaction();
    root = (NumberedNode) s.get(NumberedNode.clreplaced, new Long(root.getId()));
    NumberedNode child2 = new NumberedNode("child2");
    root.addChild(child2);
    tx.commit();
    s.close();
    replacedertInsertCount(3);
    replacedertUpdateCount(0);
}

18 View Complete Implementation : TypedOneToOneTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testCreateQuery() {
    Customer cust = new Customer();
    cust.setCustomerId("abc123");
    cust.setName("Matt");
    Address ship = new Address();
    ship.setStreet("peachtree rd");
    ship.setState("GA");
    ship.setCity("ATL");
    ship.setZip("30326");
    ship.setAddressId(new AddressId("SHIPPING", "abc123"));
    ship.setCustomer(cust);
    Address bill = new Address();
    bill.setStreet("peachtree rd");
    bill.setState("GA");
    bill.setCity("ATL");
    bill.setZip("30326");
    bill.setAddressId(new AddressId("BILLING", "abc123"));
    bill.setCustomer(cust);
    cust.setBillingAddress(bill);
    cust.setShippingAddress(ship);
    Session s = openSession();
    Transaction t = s.beginTransaction();
    s.persist(cust);
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    List results = s.createQuery("from Customer cust left join fetch cust.billingAddress where cust.customerId='abc123'").list();
    // List results = s.createQuery("from Customer cust left join fetch cust.billingAddress left join fetch cust.shippingAddress").list();
    cust = (Customer) results.get(0);
    replacedertTrue(Hibernate.isInitialized(cust.getShippingAddress()));
    replacedertTrue(Hibernate.isInitialized(cust.getBillingAddress()));
    replacedertEquals("30326", cust.getBillingAddress().getZip());
    replacedertEquals("30326", cust.getShippingAddress().getZip());
    replacedertEquals("BILLING", cust.getBillingAddress().getAddressId().getType());
    replacedertEquals("SHIPPING", cust.getShippingAddress().getAddressId().getType());
    s.delete(cust);
    t.commit();
    s.close();
}

18 View Complete Implementation : MultipleHiLoPerTableGeneratorTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testRollingBack() throws Throwable {
    Session s = openSession();
    Transaction tx = s.beginTransaction();
    int testLength = 3;
    Long lastId = null;
    for (int i = 0; i < testLength; i++) {
        Car car = new Car();
        car.setColor("color " + i);
        s.save(car);
        lastId = car.getId();
    }
    tx.rollback();
    s.close();
    s = openSession();
    tx = s.beginTransaction();
    Car car = new Car();
    car.setColor("blue");
    s.save(car);
    s.flush();
    tx.commit();
    s.close();
    replacedertEquals("id generation was rolled back", lastId.longValue() + 1, car.getId().longValue());
    s = openSession();
    tx = s.beginTransaction();
    s.createQuery("delete Car").executeUpdate();
    tx.commit();
    s.close();
}

18 View Complete Implementation : CreateTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testCreateTree() {
    clearCounts();
    Session s = openSession();
    Transaction tx = s.beginTransaction();
    Node root = new Node("root");
    Node child = new Node("child");
    root.addChild(child);
    s.persist(root);
    tx.commit();
    s.close();
    replacedertInsertCount(2);
    replacedertUpdateCount(0);
    s = openSession();
    tx = s.beginTransaction();
    System.out.println("getting");
    root = (Node) s.get(Node.clreplaced, "root");
    Node child2 = new Node("child2");
    root.addChild(child2);
    System.out.println("committing");
    tx.commit();
    s.close();
    replacedertInsertCount(3);
    replacedertUpdateCount(0);
}

18 View Complete Implementation : MapCompositeElementTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testMapCompositeElementWithFormula() {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    Part top = new Part("top", "The top part");
    Part bottom = new Part("bottom", "The bottom part");
    Product prod = new Product("Some Thing");
    prod.getParts().put("Top", top);
    prod.getParts().put("Bottom", bottom);
    s.persist(prod);
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    prod = (Product) s.get(Product.clreplaced, "Some Thing");
    replacedertEquals(prod.getParts().size(), 2);
    prod.getParts().remove("Bottom");
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    prod = (Product) s.get(Product.clreplaced, "Some Thing");
    replacedertEquals(prod.getParts().size(), 1);
    prod.getParts().put("Top", new Part("top", "The brand new top part"));
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    prod = (Product) s.get(Product.clreplaced, "Some Thing");
    replacedertEquals(prod.getParts().size(), 1);
    replacedertEquals(((Part) prod.getParts().get("Top")).getDescription(), "The brand new top part");
    s.delete(prod);
    t.commit();
    s.close();
}

18 View Complete Implementation : PartialComponentPropertyRefTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testComponentPropertyRef() {
    Person p = new Person();
    p.setIdenreplacedy(new Idenreplacedy());
    Account a = new Account();
    a.setNumber("123-12345-1236");
    a.setOwner(p);
    p.getIdenreplacedy().setName("Gavin");
    p.getIdenreplacedy().setSsn("123-12-1234");
    Session s = openSession();
    Transaction tx = s.beginTransaction();
    s.persist(p);
    s.persist(a);
    s.flush();
    s.clear();
    a = (Account) s.createQuery("from Account a left join fetch a.owner").uniqueResult();
    replacedertTrue(Hibernate.isInitialized(a.getOwner()));
    replacedertNotNull(a.getOwner());
    replacedertEquals("Gavin", a.getOwner().getIdenreplacedy().getName());
    s.clear();
    a = (Account) s.get(Account.clreplaced, "123-12345-1236");
    replacedertFalse(Hibernate.isInitialized(a.getOwner()));
    replacedertNotNull(a.getOwner());
    replacedertEquals("Gavin", a.getOwner().getIdenreplacedy().getName());
    replacedertTrue(Hibernate.isInitialized(a.getOwner()));
    s.clear();
    getSessions().evict(Account.clreplaced);
    getSessions().evict(Person.clreplaced);
    a = (Account) s.get(Account.clreplaced, "123-12345-1236");
    replacedertTrue(Hibernate.isInitialized(a.getOwner()));
    replacedertNotNull(a.getOwner());
    replacedertEquals("Gavin", a.getOwner().getIdenreplacedy().getName());
    replacedertTrue(Hibernate.isInitialized(a.getOwner()));
    s.delete(a);
    s.delete(a.getOwner());
    tx.commit();
    s.close();
}

18 View Complete Implementation : WithClauseTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testInvalidWithSemantics() {
    Session s = openSession();
    Transaction txn = s.beginTransaction();
    try {
        // PROBLEM : f.bodyWeight is a reference to a column on the Animal table; however, the 'f'
        // alias relates to the Human.friends collection which the aonther Human enreplacedy.  The issue
        // here is the way JoinSequence and Joinable (the persister) interact to generate the
        // joins relating to the sublcreplaced/superclreplaced tables
        s.createQuery("from Human h inner join h.friends as f with f.bodyWeight < :someLimit").setDouble("someLimit", 1).list();
        fail("failure expected");
    } catch (InvalidWithClauseException expected) {
    }
    try {
        s.createQuery("from Animal a inner join a.offspring o inner join o.mother as m inner join m.father as f with o.bodyWeight > 1").list();
        fail("failure expected");
    } catch (InvalidWithClauseException expected) {
    }
    try {
        s.createQuery("from Human h inner join h.offspring o with o.mother.father = :cousin").setEnreplacedy("cousin", s.load(Human.clreplaced, new Long(123))).list();
        fail("failure expected");
    } catch (InvalidWithClauseException expected) {
    }
    txn.commit();
    s.close();
}

18 View Complete Implementation : CollectionTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testValueMap() {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    User u = new User("gavin");
    u.getSessionData().put("foo", "foo value");
    u.getSessionData().put("bar", null);
    u.getEmailAddresses().add(null);
    u.getEmailAddresses().add(new Email("[email protected]"));
    u.getEmailAddresses().add(null);
    u.getEmailAddresses().add(null);
    s.persist(u);
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    User u2 = (User) s.createCriteria(User.clreplaced).uniqueResult();
    replacedertFalse(Hibernate.isInitialized(u2.getSessionData()));
    replacedertEquals(u2.getSessionData().size(), 1);
    replacedertEquals(u2.getEmailAddresses().size(), 2);
    u2.getSessionData().put("foo", "new foo value");
    u2.getEmailAddresses().set(1, new Email("[email protected]"));
    // u2.getEmailAddresses().remove(3);
    // u2.getEmailAddresses().remove(2);
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    u2 = (User) s.createCriteria(User.clreplaced).uniqueResult();
    replacedertFalse(Hibernate.isInitialized(u2.getSessionData()));
    replacedertEquals(u2.getSessionData().size(), 1);
    replacedertEquals(u2.getEmailAddresses().size(), 2);
    replacedertEquals(u2.getSessionData().get("foo"), "new foo value");
    replacedertEquals(((Email) u2.getEmailAddresses().get(1)).getAddress(), "[email protected]");
    s.delete(u2);
    t.commit();
    s.close();
}

18 View Complete Implementation : VersionTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testVersionShortCircuitFlush() {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    Person gavin = new Person("Gavin");
    new Thing("Preplacedport", gavin);
    s.persist(gavin);
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    Thing preplacedp = (Thing) s.get(Thing.clreplaced, "Preplacedport");
    preplacedp.setLongDescription("blah blah blah");
    s.createQuery("from Person").list();
    s.createQuery("from Person").list();
    s.createQuery("from Person").list();
    t.commit();
    s.close();
    replacedertEquals(preplacedp.getVersion(), 1);
    s = openSession();
    t = s.beginTransaction();
    s.createQuery("delete from Thing").executeUpdate();
    s.createQuery("delete from Person").executeUpdate();
    t.commit();
    s.close();
}

18 View Complete Implementation : FetchingTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testHibernateFetchingLazy() throws Exception {
    Session s;
    Transaction tx;
    s = openSession();
    tx = s.beginTransaction();
    Person p = new Person("Gavin", "King", "JBoss Inc");
    Stay stay = new Stay(null, new Date(), new Date(), "A380", "Blah", "Blah");
    Stay stay2 = new Stay(null, new Date(), new Date(), "A320", "Blah", "Blah");
    Stay stay3 = new Stay(null, new Date(), new Date(), "A340", "Blah", "Blah");
    stay.setOldPerson(p);
    stay2.setVeryOldPerson(p);
    stay3.setVeryOldPerson(p);
    p.addOldStay(stay);
    p.addVeryOldStay(stay2);
    p.addVeryOldStay(stay3);
    s.persist(p);
    tx.commit();
    s.clear();
    tx = s.beginTransaction();
    p = (Person) s.createQuery("select p from Person p where p.firstName = :name").setParameter("name", "Gavin").uniqueResult();
    replacedertFalse(Hibernate.isInitialized(p.getOldStays()));
    replacedertEquals(1, p.getOldStays().size());
    replacedertFalse("lazy extra is failing", Hibernate.isInitialized(p.getOldStays()));
    s.clear();
    stay = (Stay) s.get(Stay.clreplaced, stay.getId());
    replacedertTrue(!Hibernate.isInitialized(stay.getOldPerson()));
    s.clear();
    stay3 = (Stay) s.get(Stay.clreplaced, stay3.getId());
    replacedertTrue("FetchMode.JOIN should overrides lazy options", Hibernate.isInitialized(stay3.getVeryOldPerson()));
    s.delete(stay3.getVeryOldPerson());
    tx.commit();
    s.close();
}

18 View Complete Implementation : AbstractCompositeIdTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testEmbeddedCompositeIdentifierOnAbstractClreplaced() {
    MyInterfaceImpl myInterface = new MyInterfaceImpl();
    myInterface.setKey1("key1");
    myInterface.setKey2("key2");
    myInterface.setName("test");
    Session s = openSession();
    Transaction t = s.beginTransaction();
    s.save(myInterface);
    s.flush();
    s.createQuery("from MyInterface").list();
    s.delete(myInterface);
    t.commit();
    s.close();
}

18 View Complete Implementation : TypedOneToOneTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testCreateQueryNull() {
    Customer cust = new Customer();
    cust.setCustomerId("xyz123");
    cust.setName("Matt");
    Session s = openSession();
    Transaction t = s.beginTransaction();
    s.persist(cust);
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    List results = s.createQuery("from Customer cust left join fetch cust.billingAddress where cust.customerId='xyz123'").list();
    // List results = s.createQuery("from Customer cust left join fetch cust.billingAddress left join fetch cust.shippingAddress").list();
    cust = (Customer) results.get(0);
    replacedertNull(cust.getShippingAddress());
    replacedertNull(cust.getBillingAddress());
    s.delete(cust);
    t.commit();
    s.close();
}

18 View Complete Implementation : DeleteTransientEntityTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testTransientEnreplacedyDeletionCascadingToDetachedreplacedociation() {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    Address address = new Address();
    address.setInfo("123 Main St.");
    s.save(address);
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    Person p = new Person();
    p.getAddresses().add(address);
    s.delete(p);
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    Long count = (Long) s.createQuery("select count(*) from Address").list().get(0);
    replacedertEquals("delete not cascaded properly across transient enreplacedy", 0, count.longValue());
    t.commit();
    s.close();
}

18 View Complete Implementation : SybaseTimestampVersioningTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testCollectionVersion() throws Exception {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    User steve = new User("steve");
    s.persist(steve);
    Group admin = new Group("admin");
    s.persist(admin);
    t.commit();
    s.close();
    byte[] steveTimestamp = steve.getTimestamp();
    s = openSession();
    t = s.beginTransaction();
    steve = (User) s.get(User.clreplaced, steve.getId());
    admin = (Group) s.get(Group.clreplaced, admin.getId());
    steve.getGroups().add(admin);
    admin.getUsers().add(steve);
    t.commit();
    s.close();
    replacedertFalse("owner version not incremented", Hibernate.BINARY.isEqual(steveTimestamp, steve.getTimestamp()));
    steveTimestamp = steve.getTimestamp();
    s = openSession();
    t = s.beginTransaction();
    steve = (User) s.get(User.clreplaced, steve.getId());
    steve.getGroups().clear();
    t.commit();
    s.close();
    replacedertFalse("owner version not incremented", Hibernate.BINARY.isEqual(steveTimestamp, steve.getTimestamp()));
    s = openSession();
    t = s.beginTransaction();
    s.delete(s.load(User.clreplaced, steve.getId()));
    s.delete(s.load(Group.clreplaced, admin.getId()));
    t.commit();
    s.close();
}

18 View Complete Implementation : CreateTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testCreateExceptionWithGeneratedId() {
    Session s = openSession();
    Transaction tx = s.beginTransaction();
    NumberedNode dupe = new NumberedNode("dupe");
    s.persist(dupe);
    s.persist(dupe);
    tx.commit();
    s.close();
    s = openSession();
    tx = s.beginTransaction();
    try {
        s.persist(dupe);
        replacedertFalse(true);
    } catch (PersistentObjectException poe) {
    // verify that an exception is thrown!
    }
    tx.rollback();
    s.close();
    NumberedNode nondupe = new NumberedNode("nondupe");
    nondupe.addChild(dupe);
    s = openSession();
    tx = s.beginTransaction();
    try {
        s.persist(nondupe);
        replacedertFalse(true);
    } catch (PersistentObjectException poe) {
    // verify that an exception is thrown!
    }
    tx.rollback();
    s.close();
}

18 View Complete Implementation : VersionTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testCollectionNoVersion() {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    Person gavin = new Person("Gavin");
    new Task("Code", gavin);
    s.persist(gavin);
    t.commit();
    s.close();
    replacedertEquals(0, gavin.getVersion());
    s = openSession();
    t = s.beginTransaction();
    gavin = (Person) s.createCriteria(Person.clreplaced).uniqueResult();
    new Task("Doreplacedent", gavin);
    t.commit();
    s.close();
    replacedertEquals(0, gavin.getVersion());
    replacedertFalse(Hibernate.isInitialized(gavin.getTasks()));
    s = openSession();
    t = s.beginTransaction();
    gavin = (Person) s.createCriteria(Person.clreplaced).uniqueResult();
    gavin.getTasks().clear();
    t.commit();
    s.close();
    replacedertEquals(0, gavin.getVersion());
    replacedertTrue(Hibernate.isInitialized(gavin.getTasks()));
    s = openSession();
    t = s.beginTransaction();
    s.delete(gavin);
    t.commit();
    s.close();
}

18 View Complete Implementation : AbstractGeneratedPropertyTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public final void testGeneratedProperty() {
    GeneratedPropertyEnreplacedy enreplacedy = new GeneratedPropertyEnreplacedy();
    enreplacedy.setName("enreplacedy-1");
    Session s = openSession();
    Transaction t = s.beginTransaction();
    s.save(enreplacedy);
    s.flush();
    replacedertNotNull("no timestamp retrieved", enreplacedy.getLastModified());
    t.commit();
    s.close();
    byte[] bytes = enreplacedy.getLastModified();
    s = openSession();
    t = s.beginTransaction();
    enreplacedy = (GeneratedPropertyEnreplacedy) s.get(GeneratedPropertyEnreplacedy.clreplaced, enreplacedy.getId());
    replacedertTrue(Hibernate.BINARY.isEqual(bytes, enreplacedy.getLastModified()));
    t.commit();
    s.close();
    replacedertTrue(Hibernate.BINARY.isEqual(bytes, enreplacedy.getLastModified()));
    s = openSession();
    t = s.beginTransaction();
    s.delete(enreplacedy);
    t.commit();
    s.close();
}

18 View Complete Implementation : VersionTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testCollectionVersion() {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    Person gavin = new Person("Gavin");
    new Thing("Preplacedport", gavin);
    s.persist(gavin);
    t.commit();
    s.close();
    replacedertEquals(0, gavin.getVersion());
    s = openSession();
    t = s.beginTransaction();
    gavin = (Person) s.createCriteria(Person.clreplaced).uniqueResult();
    new Thing("Laptop", gavin);
    t.commit();
    s.close();
    replacedertEquals(1, gavin.getVersion());
    replacedertFalse(Hibernate.isInitialized(gavin.getThings()));
    s = openSession();
    t = s.beginTransaction();
    gavin = (Person) s.createCriteria(Person.clreplaced).uniqueResult();
    gavin.getThings().clear();
    t.commit();
    s.close();
    replacedertEquals(2, gavin.getVersion());
    replacedertTrue(Hibernate.isInitialized(gavin.getThings()));
    s = openSession();
    t = s.beginTransaction();
    s.delete(gavin);
    t.commit();
    s.close();
}

18 View Complete Implementation : IdClassTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testIdClreplaced() {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    Customer cust = new FavoriteCustomer("JBoss", "RouteOne", "Detroit");
    s.persist(cust);
    t.commit();
    s.close();
    s = openSession();
    CustomerId custId = new CustomerId("JBoss", "RouteOne");
    t = s.beginTransaction();
    cust = (Customer) s.get(Customer.clreplaced, custId);
    replacedertEquals("Detroit", cust.getAddress());
    replacedertEquals(cust.getCustomerName(), custId.getCustomerName());
    replacedertEquals(cust.getOrgName(), custId.getOrgName());
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    cust = (Customer) s.createQuery("from Customer where id.customerName = 'RouteOne'").uniqueResult();
    replacedertEquals("Detroit", cust.getAddress());
    replacedertEquals(cust.getCustomerName(), custId.getCustomerName());
    replacedertEquals(cust.getOrgName(), custId.getOrgName());
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    cust = (Customer) s.createQuery("from Customer where customerName = 'RouteOne'").uniqueResult();
    replacedertEquals("Detroit", cust.getAddress());
    replacedertEquals(cust.getCustomerName(), custId.getCustomerName());
    replacedertEquals(cust.getOrgName(), custId.getOrgName());
    s.createQuery("delete from Customer").executeUpdate();
    t.commit();
    s.close();
}