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,