-->
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: lazy @ManyToOne fk to non pkey
PostPosted: Sun Nov 23, 2008 6:06 pm 
Newbie

Joined: Tue Mar 11, 2008 4:49 am
Posts: 12
HI
I have a problem with lazy loading on @ManyToOne association mapping to unique (non primary key) column.

I've been looking in reference guide and in Hibernate in action but still missing something.

I have unidirectional ManyToOne mapping :EventLog to EventLogType

Code:
@Entity
@Table(name = "event_log")
@SequenceGenerator(name = "seq_evl", sequenceName = "sq_evl_id")
public class EventLog{
   @Id
   @Column(name = "evl_id")
   @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq_evl")
   private Long id;

   @Column(name = "evl_executor_id", nullable = false, length = 20)
   private String executorId;

   @Column(name = "evl_datetime", nullable = false)
   @Temporal(TemporalType.TIMESTAMP)
   private Date dateTime;

   @Column(name = "evl_request_id", nullable = true, length = 100)
   private String requestId;

   @ManyToOne(fetch = FetchType.LAZY,optional=false)   
   @JoinColumn(name = "evl_elt_code", referencedColumnName = "elt_code", nullable=false)
   private EventLogType type;

}


@Entity
@Table(name = "event_log_type")
@SequenceGenerator(name = "seq_elt", sequenceName = "sq_elt_id")
public class EventLogType extends AbstractDataObjectNumberId {

   @Id
   @Column(name = "elt_id", nullable = false)
   @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq_elt")
   private Long id;

   @Column(name = "elt_code", nullable = false, unique = true)
   private String code;
}



I have tried different settings including making association bidirectional, trying setting nullable or unique on association columns but still lazy loading does not work for this case.
if i just execute query:

Code:
session.createQuery("from EventLog where id = ?").setLong(0, exampleEventId).uniqueResult();

or
load object
Code:
session.load(EventLog.class, exampleEventId);


I see SQL select to load EventLog and then immediate additional SQL select to load associated eventLogType.
(Of course i do not make any navigation in my code from EventLog to EventLogType that could result in additional SELECT)

ASFAIR from my previous projects i had no problem but when associated was based on FK mapped to PK of parent table.

Can anyone explain me what is going on and why it does not work as expected.


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.