use of org.hibernate.test.onetoone.formula.Address in project hibernate-orm by hibernate.
the class NonEncapsulatedCompositeIdResultSetProcessorTest method testCompositeIdWithKeyManyToOne.
@Test
public void testCompositeIdWithKeyManyToOne() throws Exception {
final String personId = "John Doe";
Person p = new Person();
p.setName(personId);
final Address a = new Address();
a.setPerson(p);
p.setAddress(a);
a.setType("HOME");
a.setStreet("Main St");
a.setState("Sweet Home Alabama");
a.setZip("3181");
Session s = openSession();
Transaction t = s.beginTransaction();
s.persist(p);
t.commit();
s.close();
final EntityPersister personPersister = sessionFactory().getEntityPersister(Person.class.getName());
final EntityPersister addressPersister = sessionFactory().getEntityPersister(Address.class.getName());
{
final List results = getResults(addressPersister, new Callback() {
@Override
public void bind(PreparedStatement ps) throws SQLException {
ps.setString(1, personId);
ps.setString(2, "HOME");
}
@Override
public QueryParameters getQueryParameters() {
QueryParameters qp = new QueryParameters();
qp.setPositionalParameterTypes(new Type[] { addressPersister.getIdentifierType() });
qp.setPositionalParameterValues(new Object[] { a });
qp.setOptionalObject(a);
qp.setOptionalEntityName(addressPersister.getEntityName());
qp.setOptionalId(a);
qp.setLockOptions(LockOptions.NONE);
return qp;
}
});
assertEquals(1, results.size());
Object result = results.get(0);
assertNotNull(result);
}
// test loading the Person (the entity with normal id def, but mixed composite fk to Address)
{
final List results = getResults(personPersister, new Callback() {
@Override
public void bind(PreparedStatement ps) throws SQLException {
ps.setString(1, personId);
}
@Override
public QueryParameters getQueryParameters() {
QueryParameters qp = new QueryParameters();
qp.setPositionalParameterTypes(new Type[] { personPersister.getIdentifierType() });
qp.setPositionalParameterValues(new Object[] { personId });
qp.setOptionalObject(null);
qp.setOptionalEntityName(personPersister.getEntityName());
qp.setOptionalId(personId);
qp.setLockOptions(LockOptions.NONE);
return qp;
}
});
assertEquals(1, results.size());
Object result = results.get(0);
assertNotNull(result);
}
// CardField cardFieldWork = ExtraAssertions.assertTyping( CardField.class, result );
// assertEquals( cardFieldGotten, cardFieldWork );
// clean up test data
s = openSession();
s.beginTransaction();
s.createQuery("delete Address").executeUpdate();
s.createQuery("delete Person").executeUpdate();
s.getTransaction().commit();
s.close();
}
use of org.hibernate.test.onetoone.formula.Address in project hibernate-orm by hibernate.
the class KeyManyToOneWalkingTest method testWalkingKeyManyToOneGraphs.
@Test
public void testWalkingKeyManyToOneGraphs() {
// Address has a composite id with a bi-directional key-many to Person
final EntityPersister ep = (EntityPersister) sessionFactory().getClassMetadata(Address.class);
MetamodelGraphWalker.visitEntity(new LoggingAssociationVisitationStrategy(), ep);
}
Aggregations