Home JPA's Map<KEY, VALUE> query is not working correctly
Reply: 0

JPA's Map<KEY, VALUE> query is not working correctly

Maha makni
1#
Maha makni Published in 2018-02-12 12:53:21Z

I am using hibernate 4.3.6, and i have created a new mapping:

@Entity
@Table(name = "marketcamp")
public class Camp {
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "mcamp_generator")
    @SequenceGenerator(name = "mcamp_generator", sequenceName = "mcamp_seq", allocationSize = 1)
    private Long id;

And embeddable entity :

@Embeddable
public class MarketcampInfo {
//other informations
}

And finally the entity market :

   @Entity
    @Table(name = "market")
    public class Market {

        @Id
        @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "market_generator")
        @SequenceGenerator(name = "market_generator", sequenceName = "market_seq", allocationSize = 1)
        private Long id;
        @ManyToMany(fetch = FetchType.EAGER)
        @JoinTable(name = "market_camp_info", joinColumns = 
     @JoinColumn(name = "market_id"), inverseJoinColumns = @JoinColumn(name = "marketCamp_id"))
        private Map<MarketCampInfo, marketCamp> marketCamps;

I want to get all marketinfos about a marketcamp, so i build this criteria query :

CriteriaBuilder builder =  getEntityManager().getCriteriaBuilder();
        CriteriaQuery<Market> criteria = builder.createQuery(Market.class);
        Root<Market> root = criteria.from(Market.class);
        criteria.select(root);
        MapJoin<Market , MarketcampInfo , Camp> mapJoin = root.joinMap("marketCamps");
        criteria.where(builder.and(
          builder.equal(mapJoin.value() , camp))
        );
return  getEntityManager().createQuery(criteria).getResultList();

But this returns all markets that have an association with marketCampInfo and the condition about the camp is not beeen considered.

Please I want help to write the correct query.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.338553 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO