Question

     table : map__company__branches (company_id int, branch_id int, is_primary_branch tinyint(1))

    public class company
    {
     @ManyToMany(fetch = FetchType.LAZY)
     @JoinTable(name = "map__company__branches", joinColumns = { @JoinColumn(name = "company_id") })
     @MapKeyManyToMany(joinColumns = { @JoinColumn(name = "branch_id") })
         @column(name="is_primary_branch")
         Map<Branch, Boolean> branchMap;
    }

Since Boolean type is not mapped entity so its giving error "targeting an unmapped class".

Was it helpful?

Solution

For this case you need collection mapping (@ElementCollection in JPA 2.0 annotations or @CollectionOfElements in Hibernate annotations) rather than relationship mapping (@...To...).

For example, with JPA 2.0 annotations:

@ElementCollection
@CollectionTable(name = "map__company__branches",
    joinColumns = @JoinColumn(name = "company_id"))
@MapKeyJoinColumn(name = "branch_id")
@Column(name = "is_primary_branch")
Map<Branch, Boolean> branchMap; 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top