-->
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: ManyToOne when mapped not to @Id makes second request
PostPosted: Mon Jan 12, 2015 4:02 am 
Newbie

Joined: Mon Jan 12, 2015 3:56 am
Posts: 5
I have 2 objects: FiasHouse and FiasAddrObj. The source code is below.

The problem is when I list FiasHouse like this:

Code:
session.createCriteria(FiasHouse.class).setMaxResults(100).list()


after first request, Hibernate makes another 100 selects to fetch AddrObj's

When I move @Id annotation on aoguid in FiasAddrObj, everything works fine. How can I make lazy loading work?

Code:
@Entity @Table(name = "FIAS_HOUSE", schema = "fias")
@Where(clause = "ESTSTATUS = '2' or ESTSTATUS = '0'")
public class FiasHouse implements Serializable {

   @Id
   @GeneratedValue(strategy = GenerationType.IDENTITY)
   private String houseId;

   @Column(nullable = false)
   private String houseGuid;

   @ManyToOne(fetch = FetchType.LAZY)
   @JoinColumn(name = "AOGUID", referencedColumnName = "aoguid", nullable = false, updatable = false)
   private FiasAddrObj fiasAddrObj;

   //other fields
   //setters,getters
   ...
}

Code:
@Entity @Table(name = "FIAS_FIAS_ADDROBJ", schema = "fias")
@Where(clause = "LIVESTATUS=1 and ACTSTATUS=1")
public class FiasAddrObj implements Serializable {

   @Id
   private String aoId;

   @Column(nullable = false)
   private String aoGuId;

   //other fields
   //setters,getters
   ...
}


P.S. Compile-time instrumentation and adding @NaturalId to guid column doesn't help. As well as adding @LazyToOne. I'm using Hibernate 4.1.5.Final, also tried with Hibernate 4.3.5.Final.


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.