Dave Sid
Dave Sid

Reputation: 11

Can hibernate map a Java collection of different object types?

I have a Java HashMap object that contians a User object and a Room object. Can Hibernate cope with mapping this to a database, or can hibernate only deal with mapping collections that contain objects of the same type?

Many thanks,

Dave.

Upvotes: 1

Views: 343

Answers (1)

Vincent Ramdhanie
Vincent Ramdhanie

Reputation: 103135

You may want to create a common supertype for these objects. If you find that the two types do not have common foundation then maybe they do not belong in the same Map. As far as I know, mapping to two distinct types as you describe is not possible.

Upvotes: 3

Related Questions