How to display single record in the database if duplicate records are available using hibernate -
my table is:
sid fname lname subject phno --- ----- ----- -------- ----- 1 vvk v math 4444 1 vvk v read 4444 2 hari h math 5555 2 hari h read 5555 3 kalyan k math 6666 3 kalyan k read 6666
how can display single record student has take subject math or read, this:
1 vvk v math 4444
how write query in hibernate above output?
the table contains composite id on sid , subject fields
mysql mapping file is
student.hbm.xml:
<composite-id> <key-property name="sid" column="sid" type="string"/> <key-property name="subject" column="subject" type="string"/> </composite-id>
with kind of composite key, create instance of student
, set attributes key. can load desired row instance session.load()
method. follow example:
student student = new student(); student.setsid("1"); student.setsubject("math"); session.load(student.class, student);
the call session.load(student.class, student)
load persistent state of student student
instance.
Comments
Post a Comment