简体   繁体   中英

Hibernate - How to get object reference

I'm reading data from .csv file and storing those values into one table. For that table have a POJO class. that class has variable

   private Integer customerId;

mapping for that above property in hbm.xml file

     <property name="customerId" type="long">
        <column name="CUSTOMER_ID" />
    </property>

customer_id is equal to XXXX class id. based on the customer_id, I need XXXX class object without querying manually.

can you guys please help on this Thanks in Advance

I assume that your POJO is called Customer and that you have something similar to this Hibernate documentation , then you can use :

session = sessionFactory.openSession();
session.beginTransaction();
Customer myCustomer = session.load(Customer.class, <THE_ID_YOU_ARE_LOOKING>);
session.getTransaction().commit();
session.close();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM