Take the 2-minute tour ×

I can't seem to find my way out of this. Basically what I have is something like:

public class EmbeddedBase

public class EmbeddedA extends EmbeddedBase
private String name;


public class MyEntity
private Map<String, EmbeddedBase> embeddeds = new ..;


// Populate
MyEntity entity = new MyEntity();
entity.getEmbeddeds().put(EmbeddedA.class.getName(), new EmbeddedA());

// Try to query using join
From<MyEntity> from = criteria.from(MyEntity.class);
MapJoin<?,?,?> join = from.joinMap("embeddeds");
Path<?> pathToEmbeddedAName = join.value().get("name") <-- fails with attribute "name" not found

This somewhat makes sense because the underlying type of the join.value() here is "EmbeddedBase" and not "EmbeddedA". However, I do actually know and can make sure that the underlying type in my case is "EmbeddedA" (or any other descendant but I know the type for sure). I am doing so because I add a separate filter predicate to check for the key of the map which contains the class name as string, so I make sure to select the right entry in the map.

After all I'd need somelike join.value().castUnderylingJavaTypeTo(EmbeddedA.class)? Because odb correctly saves and retrieves the fields, I simply cannot access it using criteria api.. I can also not use metamodel because it is not available for me at that point.. so what am I doing wrong? I can't seem to figure any simple way out of here?

share|improve this question
so, at the time of writing the class MyEntity, you have no real knowledge of what embeddable objects you might have. but upon writing the query you are 100% sure there will exist an embedded field called "name"? how does this make sense? :) –  davogotland Dec 23 '11 at 0:20
Well because I do exactly know which descendant class is contained within the list of MyEntity however the underlying type I do have to declare for MyEntity's list is my base class because other types (which I know as well) might be added/persisted within the same list. So as I know that the query join should return a type XY I do also know that it has a field "name", the issue is simply that the JPA Implementations seem to check with the metamodel (which goes for EmbeddedBase) and doesn't find the name attribute at the time of writing the criteria query.. –  MasterOfDisaster Dec 23 '11 at 1:31
how can you be sure that the join in question will always just return objects of one specific type? –  davogotland Dec 23 '11 at 2:05
Because I am adding an additional Filter Predicate that verifies the map's key for the classname string.. :) –  MasterOfDisaster Dec 23 '11 at 2:10
what filter are you referring to? –  davogotland Dec 23 '11 at 2:41
show 11 more comments


Your Answer



Browse other questions tagged or ask your own question.