views:

91

answers:

0

I'm in the process of writing a module for an application that bulk imports data. I'm using Hibernate version 3 for data access. I receive a flat table of data let's call it products for simplicity and assume this data layout:

Name, category, sub-category
foo,   main1,  sub11

The category and sub-category fields actually refer to the lookupName column in different lookup tables, and the products table that i'm trying to insert to stores the corresponding id's from each respective lookup table, the database equivalent record or finished result for the input above one looks like this:

Name, category, sub-category
foo,   1,  5

// to get 1 and 5 lookup id's
    String hql = "from Lookup where name = :name";
    String[] paramName = new String[]{"name"};
    String[] paramValue = new String[]{"foo"};
    List<Product> products = (List<Lookup>)this.getHibernateTemplate().findByNamedParam(hql, paramName, paramValue);

My question is when working with Hibernate is to get the lookup id 1 and 5 above is my only option to run a separate query for each lookup before I can insert the product row above? I'm wondering if there is some syntactic sugar where I could supply the lookup name to my product entity and Hibernate will resolve this dynamically just before insert, possible?