Using Map<ClassB, ClassC> in JPA entities

C

Chris Ward

Hi all,

Does anyone out there have experience of using Map in JPA entities but
with a third class as the Key?

I have no problem in using the "standard" Map scenario - where the key
field is an attribute of the value object.

e.g.

@Entity
public class Department {
...

@OneToMany(fetch = EAGER)
@MapKey(name = "name")
private Map<String, Employee> employees = new HashMap<String,
Employee>();

...
}

Where the String (name) value is an attribute of the Employee class.



What I want to do is ...

@Entity
public class ClassA {
...

@OneToMany()
private Map<ClassB, ClassC> lookup = new HashMap<ClassB, ClassC>();

...
}

Where ClassB is NOT an attribute of ClassC.

Is there some funky form of the @MapKey annotation that I can use?

Many thanks for any replies on this.

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,142
Latest member
DewittMill
Top