Example usage for org.springframework.data.mongodb.core.mapping PersonPojoLongId PersonPojoLongId

List of usage examples for org.springframework.data.mongodb.core.mapping PersonPojoLongId PersonPojoLongId

Introduction

In this page you can find the example usage for org.springframework.data.mongodb.core.mapping PersonPojoLongId PersonPojoLongId.

Prototype

public PersonPojoLongId(long id, String text) 

Source Link

Usage

From source file:org.springframework.data.mongodb.core.mapping.MappingTests.java

@Test
public void testNoMappingAnnotationsUsingLongAsId() {
    PersonPojoLongId p = new PersonPojoLongId(1, "Text");
    template.insert(p);/*  ww  w. j a va  2s  .  c  o m*/
    template.updateFirst(query(where("id").is(1)), update("text", "New Text"), PersonPojoLongId.class);

    PersonPojoLongId p2 = template.findOne(query(where("id").is(1)), PersonPojoLongId.class);
    assertEquals("New Text", p2.getText());

    p.setText("Different Text");
    template.save(p);

    PersonPojoLongId p3 = template.findOne(query(where("id").is(1)), PersonPojoLongId.class);
    assertEquals("Different Text", p3.getText());

}

From source file:org.springframework.data.mongodb.core.mapping.MappingTests.java

@Test
public void testPersonWithLongDBRef() {
    PersonPojoLongId personPojoLongId = new PersonPojoLongId(12L, "PersonWithLongDBRef");
    template.insert(personPojoLongId);/*from w  ww.j  a  v a 2  s.  co  m*/

    PersonWithLongDBRef personWithLongDBRef = new PersonWithLongDBRef(21, "PersonWith", "LongDBRef",
            personPojoLongId);
    template.insert(personWithLongDBRef);

    Query q = query(where("ssn").is(21));
    PersonWithLongDBRef p2 = template.findOne(q, PersonWithLongDBRef.class);
    assertNotNull(p2);
    assertNotNull(p2.getPersonPojoLongId());
    assertEquals(12L, p2.getPersonPojoLongId().getId());
}