Gunnar Morling There were already existing tests of both key() and value() in the ORM testsuite. And they all seem to be doing the right thing. They all tend to use the overly complex "Animal" model from org.hibernate.test.hql, so I wrote a more specific domain model and tests. By my results were the same (for key at least, I still have to test value) in terms of they all worked as I would expect. So my model was:
public static enum AddressType {
HOME,
WORK,
BUSINESS
}
@Embeddable
public static class Address {
public Integer id;
String street;
String city;
}
@Entity(name = "Contact")
@Table(name = "contact")
public static class Contact {
@Id
public Integer id;
String name;
@ElementCollection
@MapKeyEnumerated(EnumType.STRING)
@MapKeyColumn(name = "addr_type")
Map<AddressType, Address> addresses = new HashMap<AddressType, Address>();
}
Below are the HQL queries I ran along with the generated SQL. Note that addr_type is the map key column.
s.createQuery( "from Contact c join c.addresses a where key(a) = 'HOME'" ).list();
- gives -
select ... where addresses1_.addr_type='HOME'
s.createQuery( "from Contact c where key(c.addresses) = 'HOME'" ).list();
- gives -
select ... where addresses1_.addr_type='HOME'
s.createQuery( "select key(a) from Contact c join c.addresses a" ).list();
- gives -
select addresses1_.addr_type as col_0_0_ ...
s.createQuery( "select key(c.addresses) from Contact c" ).list();
- gives -
select addresses1_.addr_type as col_0_0_ ...
So I am going to need you to show me a test where you see this.
|