-->
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.  [ 6 posts ] 
Author Message
 Post subject: Hibernate 3.2.1 - left join fetch broken? Behavior changed?
PostPosted: Wed Dec 13, 2006 6:14 pm 
Regular
Regular

Joined: Mon Nov 14, 2005 7:33 pm
Posts: 73
I'm a Glassfish user who has been using Hibernate 3.2 as the underlying persistence engine in Glassfish successfully for months now. It would appear that there's some unexpected behavior in Hibernate 3.2.1 that wasn't present in 3.2.0, however.

I can't left-join-fetch a lazily-loaded entity w/o a LIE (LazyInitializationException) in 3.2.1! Can one of you Glassfish-Hibernaters confirm this for me?

This exception didn't occur w/ the same code in 3.2.0 -or- when using Toplink.

Here's the entity relationship:

Code:
@Entity
@Table(name="pub.\"ord-traf\"")
public class OrderTraffic implements Serializable
{
  /**
   * EmbeddedId primary key field
   */
  @EmbeddedId
  protected OrderTrafficPK orderTrafficPK;

  @ManyToOne(fetch=FetchType.LAZY)
  @JoinColumn(name="\"carrier-no\"", insertable=false, updatable=false)
  private Vendor vendor;
.....................
}

...the PK class for above entity...

@Embeddable
public class OrderTrafficPK implements Serializable
{
  @Column(name="\"ar-entity\"", nullable=false)
  private String arEntity;

  @Column(name="\"load-no\"", nullable=false)
  private String loadNo;

  @Column(name="\"plant\"", nullable=false)
  private String plant;
.....................
}

@Entity
@Table(name="pub.\"vendor\"")
public class Vendor implements Serializable
{
  @Id
  @Column(name="\"Vendor-code\"", nullable=false)
  private String vendorcode;

  @Column(name="\"Name\"", nullable=false)
  private String name;
 
  @Column(name="\"Zip-code\"", nullable=false)
  private String zipcode;
.....................
}


As you can see, I have an entity called "OrderTraffic" that has a uni-directional one-to-one relationship w/ "Vendor". OrderTraffic has a composite PK, Vendor does not. I tried @OneToOne as well...the exception is the same.

Here's the JPA-QL to call them:

Code:
String query = "select ot from OrderTraffic ot left join fetch ot.vendor";


At runtime, I see this query (exactly as expected):

Code:
Hibernate:
    /* select
        ot
    from
        OrderTraffic ot
    left join
        fetch ot.vendor
    where
        ot.shipDate = :shipDate
        and ot.shipDate > :maxShipDate
    order by
        ot.carrierNo */ select
            ordertraff0_."ar-entity" as ar1_128_0_,
            ordertraff0_."load-no" as load2_128_0_,
            ordertraff0_."plant" as plant3_128_0_,
            vendor1_."Vendor-code" as Vendor1_131_1_,
            ordertraff0_."truck-no" as truck4_128_0_,
            ordertraff0_."trailer-no" as trailer5_128_0_,
            ordertraff0_."can-type" as can6_128_0_,
            ordertraff0_."carrier-no" as carrier7_128_0_,
            ordertraff0_."dept-time" as dept8_128_0_,
            ordertraff0_."ship-date" as ship9_128_0_,
            ordertraff0_."seal-no" as seal10_128_0_,
            ordertraff0_."spec-instr" as spec11_128_0_,
            ordertraff0_."trailer-ad" as trailer12_128_0_,
            ordertraff0_."trailer-at" as trailer13_128_0_,
            ordertraff0_."max-net" as max14_128_0_,
            ordertraff0_."est-freight" as est15_128_0_,
            ordertraff0_."act-freight" as act16_128_0_,
            ordertraff0_."lock-load" as lock17_128_0_,
            vendor1_."Name" as Name2_131_1_,
            vendor1_."Zip-code" as Zip3_131_1_,
            vendor1_."Telephone" as Telephone4_131_1_,
            vendor1_."Contact" as Contact5_131_1_
        from
            pub."ord-traf" ordertraff0_
        left outer join
            pub."vendor" vendor1_
                on ordertraff0_."carrier-no"=vendor1_."Vendor-code"
        where
            ordertraff0_."ship-date"=?
            and ordertraff0_."ship-date">?
        order by
            ordertraff0_."carrier-no"


I'm calling it in a very straightforward way in a JSF managed bean and simply listing the entity data in a dataTable...there's nothing special going on there.

Here's the exception:

Code:
executePhase(RENDER_RESPONSE 6,com.sun.faces.context.FacesContextImpl@2a1d96) threw exception
javax.faces.FacesException: javax.el.ELException: org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
        at javax.faces.component.UIOutput.getValue(UIOutput.java:176)
        at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:100)
        at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:279)
        at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:207)
        at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:848)
        at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:240)
        at com.sun.faces.renderkit.html_basic.TableRenderer.encodeChildren(TableRenderer.java:309)
        at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:828)
...........................


What's the problem? I'm fetching it before it is rendered in the view...yet it fails when using Hibernate 3.2.1...and it did not in 3.2.0, or Toplink...like I said.

Help is much appreciated, thanks!!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 17, 2006 6:28 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
it should work, can you provide a minimal runnable test case (no JSF) and post it to JIRA

_________________
Emmanuel


Top
 Profile  
 
 Post subject: update using JBoss/Hibernate
PostPosted: Mon Jan 29, 2007 3:37 pm 
Regular
Regular

Joined: Mon Nov 14, 2005 7:33 pm
Posts: 73
emmanuel wrote:
it should work, can you provide a minimal runnable test case (no JSF) and post it to JIRA


I moved to JBoss 4.0.5.GA and am having the same problem, I'm getting LIE exceptions on simple join fetch cases where I shouldn't be.

Here's another example, using EJB3/Hibernate:

Code:
@Entity
@Table(name="pub."vendor"")
public class Vendor implements Serializable
{
  @Id
  @Column(name="`Vendor-code`", nullable=false)
  private String vendorcode;

  @OneToMany(mappedBy="vendor", fetch=FetchType.LAZY)
  private List<OrderTraffic> orderTraffics;
.................................
}

@Entity
@Table(name="pub."ord-traf"")
public class OrderTraffic implements Serializable
{
   @Id
   @Column(name="`load-no`", nullable=false)
   private String loadNo;

  @Column(name="`carrier-no`")
  private String carrierNo;
   
  @ManyToOne(fetch=FetchType.LAZY)
  @JoinColumn(name="`carrier-no`", insertable=false, updatable=false)
  private Vendor vendor;
.................................
}


...queried like so:

Code:
select ot from OrderTraffic ot left join fetch ot.vendor


It produced correct SQL, the table is being joined but it yields this exception:

Code:
Caused by: org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
   at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:60)
   at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111)
   at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:198)
.........................................


It also happens the other way around...I get a LIE on any LAZY relationship I try to join-fetch against...even if I use a plain servlet to simply test-pull some records.

If you still think this is an issue and not just an error on my part I'll prepare a small sample app to attach to a JIRA report.

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 29, 2007 6:05 pm 
Regular
Regular

Joined: Mon Nov 14, 2005 7:33 pm
Posts: 73
Wow, this is really strange. When I modified the test app I made for the JIRA issue, using MSSQL 2000 (since I cannot create tables on our Progress server) - it works fine.

Why would this work for MSSQL but not for Progress?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 29, 2007 6:56 pm 
Regular
Regular

Joined: Mon Nov 14, 2005 7:33 pm
Posts: 73
After further investigation...I found a "work-around" but it's pretty rough. The reason it was throwing a LIE was due to the object being null on some of the records. I surrounded the call to the many-to-one related entity w/ a try/catch block (ignoring the exception when caught) and am able to get what I need.

This may be by design, I don't know. Either way, it'd be nice to simply have a null for the missing record/entity vs. a LIE being thrown.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 02, 2007 5:39 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
tsar bomba wrote:
This may be by design, I don't know. Either way, it'd be nice to simply have a null for the missing record/entity vs. a LIE being thrown.


@NotFound

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.