[morphia] Non-unique IDs

2 views
Skip to first unread message

Beer Brother

unread,
Apr 28, 2010, 11:21:40 AM4/28/10
to Morphia
I have following Eninty class:
@Entity(value="qualifications")
public class Qualification extends AbstractMongoEntity {

private String title;
@Property(value = "full_name")
private String fullName;

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public String getFullName() {
return fullName;
}

public void setFullName(String fullName) {
this.fullName = fullName;
}

@Override
public String toString() {
return "[_id='" + this.getId() + "', title='" + this.title +
"', full_title='" + this.fullName + "']";
}
}

and method for testing:

public class QualificationsDAOTest {

Mongo mongo;
Morphia morphia;
QualificationsDAO dao;

@Before
public void setUp() throws UnknownHostException {
mongo = new Mongo();
morphia = new Morphia();
morphia.map(Qualification.class);
dao = new QualificationsDAO(mongo, morphia, "sro");
}

@Test
public void testQualification() {
Qualification q0 = new Qualification();
q0.setTitle("Title 1");
q0.setFullName("First itm full name");
dao.save(q0);

Qualification q1 = new Qualification();
q1.setTitle("Title 2");
q1.setFullName("Second item full name");
dao.save(q1);

Qualification q2 = new Qualification();
q2.setTitle("Title 3");
q2.setFullName("3d item full name");
dao.save(q2);
}

@Test
public void testQualificationsList() {
Iterator<Qualification> i = dao.find().asList().iterator();
while (i.hasNext()) {
System.out.println(i.next().getId());
}

}
}

In output i recive following (same ids):
[_id='4bd852465d43f3bcd950db84', title='Title 1', full_title='First
itm full name']
[_id='4bd852465d43f3bcda50db84', title='Title 2', full_title='Second
item full name']
[_id='4bd852465d43f3bcdb50db84', title='Title 3', full_title='3d item
full name']

Mongo is 1.4.0, Morphia 0.93-SNAPSHOOT

Ólafur Gauti Guðmundsson

unread,
Apr 28, 2010, 11:25:32 AM4/28/10
to Morphia
Hi,
Actually, if you inspect these IDs more closely, you will see that
they are not identical.

4bd852465d43f3bcd-9-50db84
4bd852465d43f3bcd-a-50db84
4bd852465d43f3bcd-b-50db84

I think what's confusing you is the fact that they start and end with
the same letters.

Regards,
OGG
Reply all
Reply to author
Forward
0 new messages