This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring in Action (5th edition) and have Craig Walls on-line!
See this thread for details.
Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Accessing parent table data  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Friends,

I have 2 pojos and its mapping files as follows:

public class OutsourcedProduct
{
private Long id;
private Vendor toBeRepairedBy;
private Set outsourcedProductReceiptList = new HashSet();
......
......
getters and setters
}

public class OutsourcedProductReceipt
{
private Long id;
private OutsourcedProduct parentId;
......
......
getters and setters
}

<hibernate-mapping>
<class name="my.app.OutsourcedProduct" table="outsourced_product">
<id name="id" column="id">
<generator class="native" />
</id>
<many-to-one name="toBeRepairedBy" class="my.app.Vendor" column="toBeRepairedBy" not-null="true" />
<many-to-one name="parentId" class="my.app.ServiceEntry" column="parentId" not-null="true" />
<set name="outsourcedProductReceiptList" inverse="true" lazy="true" table="outsourced_product_receipt">
<key column="parentId" not-null="true" />
<one-to-many class="my.app.OutsourcedProductReceipt" />
</set>
</class>
</hibernate-mapping>

<hibernate-mapping>
<class name="my.app.OutsourcedProductReceipt" table="outsourced_product_receipt">
<id name="id" column="id">
<generator class="native" />
</id>
<many-to-one name="parentId" class="my.app.OutsourcedProduct" column="parentId" not-null="true" />
</class>
</hibernate-mapping>

I want to access the vendor name of 'OutsourcedProduct' from 'OutsourcedProductReceipt'

outsourcedProductReceiptEntry.getParentId().getToBeRepairedBy().getVendorName()

What changes is required in the following query or in pojos and mpping files to acces the vendor name of

OutsourcedProduct?

query = _sessionFactory.getCurrentSession().createQuery("from
OutsourcedProduct inner join fetch outsourcedProduct.parentId
inner join fetch utsourcedProduct.toBeRepairedBy
where outsourcedProduct.parentId = arentId order by
outsourcedProduct.id");

I am a newbie, any help regarding this is greatly appreciated. I am using hibernate 3.x

Thank you.

Sudheer
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not really sure what you're trying to do in that query, but i think you don't need to do those joins. Hibernate will do that for you - that's the point of the mapping. You only need to select the OusourcedProductReceiped you want then use outsourcedProductReceiptEntry.getParentId().getToBeRepairedBy().getVendorName()

Usually you use joins in your queries when you didn't mapped that relation.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!