Hibernate/JPA : this criteria query does not contain implicit ON clause -


jpwh book says join operation in criteria query hibernate produces on clause foreign key constraint. i've added these foreign key constraints on database:

alter table bid add foreign key (bidder_id) references user (id) alter table bid add foreign key (item_id) references item (id) alter table item add foreign key (seller_id) references item (id) 

so expected criteria query:

private static void implicitjoin(entitymanager em) {     criteriabuilder cb = em.getcriteriabuilder();     criteriaquery criteria = cb.createquery();      root<bid> b = criteria.from(bid.class);     criteria.select(b).where(             cb.equal(                     b.get("item").get("seller").get("username"), "johndoe")     );      typedquery<item> query = em.createquery(criteria);     list<item> results = query.getresultlist(); } 

translated like:

select b.* bid b inner join item on b.item_id = i.id inner join user u on i.seller_id = u.id u.username = 'johndoe'; 

but sql statement:

     /* select         generatedalias0              bid generatedalias0              generatedalias0.item.seller.username=:param0 */ select             bid0_.bid_id bid_id1_0_,             bid0_.bidder_id bidder_i2_0_,             bid0_.item_id item_id3_0_                      bid bid0_ cross          join             item item1_ cross          join             user user2_                      bid0_.item_id=item1_.id              , item1_.seller_id=user2_.id              , user2_.username=? 

how can put bid0_.item_id=item1_.id , item1_.seller_id=user2_.id on clause? possible? here entities:

@entity @table(name = "bid") public class bid implements serializable {      @id @generatedvalue     @column(name = "bid_id")     private long id = null;      @manytoone     @joincolumn(name = "item_id", nullable = false, updatable = false, insertable = false)     private item item;      @manytoone     @joincolumn(name = "bidder_id", nullable = false, updatable = false)     private user bidder; }  @entity @table(name = "item") public class item implements serializable {      @id     private long id = null;      private string name;     @manytoone(fetch = fetchtype.eager)     @joincolumn(name = "seller_id", nullable = false)     private user seller;      @onetomany(mappedby = "item", fetch = fetchtype.lazy)     private list<bid> bids; }  @entity @table(name = "user") public class user implements serializable {      @id     private long id = null;     private string firstname;     private string lastname;     private string username; // unique , immutable } 


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -