Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gsmet/0652294523b2c48efe72668ccc0a6e1c to your computer and use it in GitHub Desktop.
Save gsmet/0652294523b2c48efe72668ccc0a6e1c to your computer and use it in GitHub Desktop.
/*
* Hibernate OGM, Domain model persistence for NoSQL datastores
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.ogm.datastore.mongodb.test.mapping;
import static org.hibernate.ogm.datastore.mongodb.utils.MongoDBTestHelper.assertDbObject;
import org.hibernate.Transaction;
import org.hibernate.ogm.OgmSession;
import org.hibernate.ogm.backendtck.embeddable.Address;
import org.hibernate.ogm.backendtck.embeddable.MultiAddressAccount;
import org.hibernate.ogm.utils.OgmTestCase;
import org.hibernate.ogm.utils.TestForIssue;
import org.junit.Test;
/**
* @author Guillaume Smet
*/
public class ElementCollectionOfEmbeddableWithNamedColumnMappingTest extends OgmTestCase {
@Test
@TestForIssue(jiraKey = "OGM-893")
public void testMappingForElementCollectionWithNamedColumn() {
OgmSession session = openSession();
Transaction transaction = session.beginTransaction();
Address address = new Address();
address.setCity( "Paris" );
address.setZipCode( "75007" );
MultiAddressAccount account = new MultiAddressAccount();
account.setLogin( "gunnar" );
account.getAddresses().add( address );
session.persist( account );
transaction.commit();
session.clear();
assertDbObject(
session.getSessionFactory(),
// collection
"MultiAddressAccount",
// query
"{ '_id' : '" + account.getLogin() + "' }",
// fields
null,
// expected
"{ " +
"'_id' : '" + account.getLogin() + "', " +
"'addresses' : [" +
"{ 'city' : 'Paris', 'postal_code' : '75007' }" +
"]" +
"}"
);
}
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] { MultiAddressAccount.class };
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment