-->
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: component and lazy-loading
PostPosted: Fri Apr 02, 2010 7:15 pm 
Newbie

Joined: Fri Apr 02, 2010 6:46 pm
Posts: 1
Hi,

I use nHibernate 2.1.2 but 'lazy' attribute on component doesn't seem to be supported. Here is a sample :
Code:
class Employee {
  public int? Id{get;set;}
  public string Name {get;set;}
  public Document Resume {get;set;}
}

class Document {
  public string FileName {get;set;}
  public string FileType {get;set;}
  public byte[] File {get;set;}
}

create table T_EMPLOYEE(
  ID_EMPLOYEE int identity(1,1),
  NAME varchar(50),
  RESUME_FILE_NAME varchar(50),
  RESUME_FILE_TYPE varchar(5),
  RESUME_FILE varbinary(MAX)
) ON [DATA] TEXTIMAGE_ON [BLOB]


Mapping is of course :

Code:
<class name="Employee" table="T_EMPLOYEE">
    <id name="Id" column="ID_EMPLOYEE">
      <generator class="native"/>
    </id>
    <property name="Name" column="NAME"/>
    <component name="Resume" lazy="true">
      <property name="FileName" column="RESUME_FILE_NAME"/>
      <property name="FileType" column="RESUME_FILE_TYPE"/>
      <property name="File" column="RESUME_FILE" type="BinaryBlob"/>
    </component>
</class>


I think it is far simpler than a separate table (T_EMPLOYEE_RESUME), an additional mapping and a one-to-one. And anyway the 'Document' class is pretty generic and I would like to use it for other objects (Invoice, etc...) and it is impossible to map the same class many times (unless it is a component).

So, my goal is to write :
HQL query for multiple results : from Employee
HQL query for a single result : from Employee e left join fetch e.Resume where e.Id=:id

Unfortunately the SQL query loads RESUME_FILE_NAME, RESUME_FILE_TYPE and RESUME_FILE even if I don't fetch 'Resume' in the hql query (join fetch may not be the right syntax, it is not really documented).

Any idea ?

Thanks,


Top
 Profile  
 
 Post subject: Re: component and lazy-loading
PostPosted: Thu Apr 08, 2010 2:36 pm 
Newbie

Joined: Tue Mar 23, 2010 10:41 pm
Posts: 9
Hello,

Lazyloading for Components and Properties have just recently been introduced and is available in the latest version from Trunk (3.0 Alpha).

The lazyloading works fine, but i have a problem that i cannot call any methods on the an Object (Proxy) with lazy Properties/Components.
I dont know why this is happening - maybe it is me doing something wrong.

If you are able to check out the latest code from trunk, please let me know if you can call any methods on the object containing the lazy component, soo i know that it is me who have fucked something up. :)


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.