i have 2 table follows
@entity @table (name="booking_basic") public class booking_basic { @id @generatedvalue @column (name="booking_id") private int booking_id; @genericgenerator(name="foreign", strategy="foreign", parameters={@org.hibernate.annotations.parameter(name="property", value="organizer_basic")}) @column (name="org_id") private int org_id; @onetoone(fetch=fetchtype.eager, optional=true) @primarykeyjoincolumn @cascade({org.hibernate.annotations.cascadetype.save_update}) private organizer_basic organizer_basic; ....
another
@entity @table(name="organizer_basic") public class organizer_basic { @id @generatedvalue @column(name="org_id") private int org_id; @column(name="name") private string name; @onetoone(cascade={javax.persistence.cascadetype.all}, fetch=fetchtype.lazy, mappedby="organizer_basic") @joincolumn(name="org_id") private booking_basic booking_basic; .....
now organizers name based on booking id, if booking_basic have booking_id 1 , org_id = 15, access organizer name org_id 15.
session session = hibernatesessionfactory.getsessionfactory().opensession(); transaction transaction = null; try { transaction = session.begintransaction(); query query = session.createquery("from booking_basic"); list<booking_basic> booking_basic = query.list(); for(booking_basic b : booking_basic) system.out.print("booking type : " + b.getorganizer_basic().getname()); } transaction.commit(); } catch (exception e) { e.printstacktrace(); transaction.rollback(); }
but when try run it, it's giving me null pointer exception. body have idea, please me.
try this:
session.createquery("from booking_basic b left join b.organizer_basic o");
Comments
Post a Comment