-->
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: Annotation - ManyToOne lazy loading doesnt work in this case
PostPosted: Tue Mar 04, 2008 6:54 am 
Newbie

Joined: Thu Apr 26, 2007 8:26 pm
Posts: 2
Hello guys,

I am testing JPA annotation with Hibernate, but lazy loading doesn't work in my case where the FK in Stock is marketCode, a CHAR(2), but marketCode is not a PK in StockMarket.

I have two entities:

Code:
@Entity
@Table(name = "stock")
public class Stock extends BaseObject {
   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   private Integer id;
..
   @ManyToOne(fetch = FetchType.LAZY)
   @JoinColumn(name = "marketCode", referencedColumnName = "marketCode", nullable = false, unique = false, insertable = false, updatable = false)
   private StockMarket stockMarket;

..
}

@Entity
@Table(name="stock_market")
public class StockMarket extends BaseObject {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
   private Integer id;

..
   @OneToMany(mappedBy="marketCode", cascade = CascadeType.ALL, fetch=FetchType.LAZY)
   @JoinColumn(name = "marketCode", referencedColumnName = "marketCode")
   private Set<Stock> stocks = new HashSet<Stock>(0);
..
}


Lazy loading works fine from StockMarket to Stock, but when I get Stock from DB, StockMarket will also be fetched.

Could anyone please point me to the right direction?

Thanks a lot in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 06, 2008 2:28 am 
Newbie

Joined: Thu Apr 26, 2007 8:26 pm
Posts: 2
Does anyone have a suggestion? pls!


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.