Examples of Husband


Examples of org.hibernate.examples.mapping.associations.onetoone.bidirectionalManyToOne.Husband

    }

    @Test
    public void bidirectionalManyToOne() throws Exception {

        Husband husband = new Husband();
        husband.setName("Alex");

        Wife wife = new Wife();
        wife.setName("Bea");

        husband.setWife(wife);
        wife.setHusband(husband);
        em.persist(husband);
        em.persist(wife);
        em.flush();
        em.clear();

        husband = em.find(Husband.class, husband.getId());
        assertThat(husband).isNotNull();
        assertThat(husband.getWife()).isNotNull();
        em.clear();

        wife = em.find(Wife.class, wife.getId());
        assertThat(wife).isNotNull();

        husband = wife.getHusband();
        assertThat(husband).isNotNull();

        Wife bea2 = new Wife();
        em.persist(bea2);
        bea2.setName("Still Bea");

        husband.setWife(bea2);
        wife.setHusband(null);
        bea2.setHusband(husband);

        em.persist(husband);
        em.persist(bea2);
        em.flush();
        em.clear();


        husband = em.find(Husband.class, husband.getId());
        assertThat(husband).isNotNull();
        assertThat(husband.getWife()).isNotNull();
        assertThat(husband.getWife().getHusband()).isEqualTo(husband);

        em.clear();

        wife = em.find(Wife.class, wife.getId());
        assertThat(wife).isNotNull();
        assertThat(wife.getHusband()).isNull();
        em.remove(wife);

        bea2 = em.find(Wife.class, bea2.getId());
        assertThat(bea2).isNotNull();

        husband = bea2.getHusband();
        assertThat(husband).isNotNull();

        bea2.setHusband(null);
        husband.setWife(null);
        em.remove(husband);
        em.remove(wife);
        em.flush();
    }
View Full Code Here

Examples of org.hibernate.ogm.backendtck.associations.onetoone.Husband

  @Before
  public void prepareDb() throws Exception {
    getTransactionManager().begin();
    EntityManager em = getFactory().createEntityManager();

    husband = new Husband( "frederic" );
    husband.setName( "Frederic Joliot-Curie" );

    wife = new Wife( "wife" );
    wife.setName( "Irene Joliot-Curie" );
    wife.setHusband( husband );
View Full Code Here

Examples of org.hibernate.ogm.backendtck.associations.onetoone.Husband

  public void testAssociationStorageSettingIsIgnoredForBidirectionalManyToOneMapping() throws Exception {
    OgmSession session = openSession();
    Transaction transaction = session.beginTransaction();

    // Given, When
    Husband husband = new Husband( "alex" );
    husband.setName( "Alex" );
    session.persist( husband );

    Wife wife = new Wife( "bea" );
    wife.setName( "Bea" );
    husband.setWife( wife );
    wife.setHusband( husband );
    session.persist( wife );

    transaction.commit();
    session.clear();

    transaction = session.beginTransaction();

    // Then
    assertDbObject(
        session.getSessionFactory(),
        // collection
        "Wife",
        // query
        "{ '_id' : 'bea' }",
        // expected
        "{ " +
          "'_id' : 'bea', " +
          "'name' : 'Bea'," +
          "'husband' : 'alex'" +
        "}"
    );

    assertDbObject(
        session.getSessionFactory(),
        // collection
        "Husband",
        // query
        "{ '_id' : 'alex' }",
        // expected
        "{ " +
          "'_id' : 'alex', " +
          "'name' : 'Alex'," +
          "'wife' : 'bea'" +
        "}"
    );

    // Clean-Up
    husband = (Husband) session.get( Husband.class, husband.getId() );
    wife = (Wife) session.get( Wife.class, wife.getId() );
    session.delete( wife );
    session.delete( husband );

    transaction.commit();
View Full Code Here

Examples of org.hibernate.ogm.backendtck.associations.onetoone.Husband

  public void testBidirectionalManyToOneMapping() throws Exception {
    OgmSession session = openSession();
    Transaction transaction = session.beginTransaction();

    // Given, When
    Husband husband = new Husband( "alex" );
    husband.setName( "Alex" );
    session.persist( husband );

    Wife wife = new Wife( "bea" );
    wife.setName( "Bea" );
    husband.setWife( wife );
    wife.setHusband( husband );
    session.persist( wife );

    transaction.commit();
    session.clear();

    transaction = session.beginTransaction();

    // Then
    assertDbObject(
        session.getSessionFactory(),
        // collection
        "Wife",
        // query
        "{ '_id' : 'bea' }",
        // expected
        "{ " +
          "'_id' : 'bea', " +
          "'name' : 'Bea'," +
          "'husband' : 'alex'" +
        "}"
    );

    assertDbObject(
        session.getSessionFactory(),
        // collection
        "Husband",
        // query
        "{ '_id' : 'alex' }",
        // expected
        "{ " +
          "'_id' : 'alex', " +
          "'name' : 'Alex'," +
          "'wife' : 'bea'" +
        "}"
    );

    // Clean-Up
    husband = (Husband) session.get( Husband.class, husband.getId() );
    wife = (Wife) session.get( Wife.class, wife.getId() );
    session.delete( wife );
    session.delete( husband );

    transaction.commit();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.