-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: A problem with FetchProfile
PostPosted: Wed Nov 02, 2011 11:44 am 
Newbie

Joined: Wed Nov 02, 2011 11:20 am
Posts: 1
Hi all,

I'm a newbie in Hibernate, sorry for a possible dull question.
I'm using in my project @FetchProfile in such way:
Code:
@FetchProfile(name = "invoice-details", fetchOverrides = {
      @FetchProfile.FetchOverride(entity=Invoice.class, association="agreement", mode = FetchMode.JOIN),
      @FetchProfile.FetchOverride(entity=Invoice.class, association="currency", mode= FetchMode.JOIN)
   })
...
@JoinColumn(name = "inv_agr_id", referencedColumnName = "agr_id", nullable = true)
@ManyToOne(fetch = FetchType.LAZY)
private Agreement agreement;
...
@JoinColumn(name = "inv_currency", referencedColumnName = "curr_id", nullable = true)
@ManyToOne(fetch = FetchType.LAZY)
private Currency currency;
... further entity code

When I start a test:
Code:
Session sess = HibernateUtil.getSessionFactory().openSession();
sess.enableFetchProfile("invoice-details");
Transaction tx = sess.beginTransaction();
Invoice i = (Invoice) sess.get(Invoice.class, 1);
tx.commit();
sess.close();
System.out.println("ID:"+i.getInvId());
System.out.println("Agr:"+i.getAgreement().getAgrNumber());
System.out.println("Curr:"+i.getCurrency().getCurrName());

I get an exception: org.hibernate.LazyInitializationException: could not initialize proxy - no Session
I've found that the error appears on the last line of the code.
It seems, that join fetch works only for agreements and skips currencies. When I change the order in @FetchProfile declaration, join fetch swaps too. In other words, @FetchProfile works only for the first line of the declaration.
In my opinion, both objects (agreements and currency) should be initialized.
Does anyone know where I'm wrong? Thanks.


Top
 Profile  
 
 Post subject: Re: A problem with FetchProfile
PostPosted: Thu Nov 10, 2011 1:26 am 
Newbie

Joined: Thu Nov 10, 2011 1:20 am
Posts: 1
Hi,
My name is susan dressler.
I am new here,

Thanks,

Susan dressler

_________________
Monetize your website with ad2com


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.