Posts

Showing posts with the label hibernate-mapping

why select query in hibernate returning null value

Image
Clash Royale CLAN TAG #URR8PPP why select query in hibernate returning null value executing these hql... and returning null but in client server i can see output in mysql. Hibernate: alter table Product add constraint FKj4jgrmm2hxt9q00jqrvipjqoa foreign key (buyer_buyerId) references Buyer (buyerId) Hibernate: alter table Product add constraint FK4d4c781mh5deww0h3ukw66eu6 foreign key (seller_sellerId) references Seller (sellerId) Hibernate: select product0_.productId as productI1_1_, product0_.buyer_buyerId as buyer_bu7_1_, product0_.currentStockNumbers as currentS2_1_, product0_.price as price3_1_, product0_.productCategory as productC4_1_, product0_.productName as productN5_1_, product0_.remarks as remarks6_1_, product0_.seller_sellerId as seller_s8_1_ from Product product0_ where product0_.productCategory like 'mobile' Hibernate: select seller0_.sellerId as sellerId1_2_0_, seller0_.sellerName as sellerNa2_2_0_ from Seller seller0_ where seller0_.sellerId=? Hibernate: select ...

How to use one to one/zero mapping in hibernate

Image
Clash Royale CLAN TAG #URR8PPP How to use one to one/zero mapping in hibernate Suppose I have two tables: Person And Vehicle Person record can exist independently , that means, a person may or may not associated with a vehicle. But the Vehicle record can not exist without person. In the nutshell, Vehicle table has Person_Id has foreign key, where Person_Id is the primary key of the person table. Now to define this relationship in hibernate I have used one to one mapping as follows: public class Person { private int person_id; @OnetoOne(mappedBy = "person", cascade = CascadeType.ALL) private Vehicle vehicle; } public class Vehicle { private int vehicle_id; @OnetoOne(fetch = FetchType.LAZY) @JoinColumn(name = "person_id") private Person person; } Now, when I try to save the Person who has Vehicle, the person objects gets saved successfully. I just use session.save(person) and both the objects gets saved successfully. On the other hand, ...