-->
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.  [ 1 post ] 
Author Message
 Post subject: join fetch not hydrating proxy
PostPosted: Wed Sep 08, 2010 12:58 pm 
Beginner
Beginner

Joined: Thu Nov 20, 2003 10:16 pm
Posts: 28
Location: Los Angeles, CA
I have a very strange issue where Hibernate isn't hydrating a specific many-to-one relationship. I am using 3.5.5 with annotations. Here are my domain classes (watered down for relevance - e.g., getters/setters not displayed):

Code:
@Entity
@Table(name = "PHYSICIAN")
public class Physician extends VersionedPersistentEntity
{
  @OneToMany(mappedBy = "physician")
  private Set<PhysicianInsurance> acceptedInsurance;
}

@Entity
@Table(name = "PHYSICIAN_INSURANCE")
public class PhysicianInsurance extends VersionedPersistentEntity
{
  @Column(name = "PHYS_INS_ID", nullable = false)
  @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "PhysicianInsuranceIdGenerator")
  @Id
  @SequenceGenerator(name = "PhysicianInsuranceIdGenerator", sequenceName = "PHYS_INS_ID_SEQ")
  private Long id;

  @JoinColumn(name = "INS_ID")
  @ManyToOne(fetch = FetchType.LAZY)
  private InsuranceProduct insuranceProduct;

  @JoinColumn(name = "PHYS_ID")
  @ManyToOne(fetch = FetchType.LAZY)
  private Physician physician;
}

@Entity
@Table(name = "INSURANCE")
public class InsuranceProduct extends ActivatableEntity implements SourceableEntity
{
  @Column(name = "INS_ID", nullable = false)
  @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "InsuranceProductIdGenerator")
  @Id
  @SequenceGenerator(name = "InsuranceProductIdGenerator", sequenceName = "INS_ID_SEQ")
  private Long id;

  @Basic
  @Column(name = "INS_NAME", nullable = false)
  private String name;

  @Basic
  @Column(name = "INS_SYS_CD")
  private String systemCode;
}


In my code, I'm trying to retrieve a list of PhysicianInsurance object with the insuranceProduct and physician relationships prefetched. What I'm seeing is the physician property is being hydrated, but the insuranceProduct still remains a proxy. Here is my relevant DAO code:

Code:
      StringBuffer hql = new StringBuffer();

      hql.append(StringUtils.join(new String[]
          {
            "select physicianInsurance from " + PhysicianInsurance.class.getCanonicalName() + " physicianInsurance",
            "join fetch physicianInsurance.physician physician",
            "join fetch physicianInsurance.insuranceProduct insurance",
            "where physician.id = :physicianId",
            "order by physicianInsurance.id"
          }, " "));

      // Build query.
      Query query = session.createQuery(hql.toString());
      query.setReadOnly(true);
      query.setFirstResult(1);
      query.setMaxResults(100);

      query.setParameter("physicianId", somePhysicianId);

      // Execute query.
      List<PhysicianInsurance> insurances = query.list();


I am finding I have to do an ugly workaround of retrieving the InsuranceProducts in a separate query, and then associating them with the PhysicianInsurance objects manually in memory. Doesn't seem like I should need to do this. Any ideas out there? Thanks in advance.

Michael


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

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.