Hi guys,
I would appreciate any tips regarding this issue. I just can't get it working. I have two classes, Insurance and UploadedFile. Insurance has exactly one column referring to UploadedFile (primary key fileId).
The hibernate mappings:
Code:
<hibernate-mapping package="uws">
<class name="Insurance">
<id name="insuranceId">
<generator class="native"/>
</id>
<property name="name"/>
<property name="description"/>
<one-to-one name="fileId" class="UploadedFile" cascade="all" constrained="true" lazy="false" fetch="join"/>
</class>
<class name="UploadedFile">
<id name="fileId">
<generator class="native"/>
</id>
<property name="fileName"/>
<property name="path"/>
</class>
</hibernate-mapping>
So when I try to insert it, hibernate inserts one row to insurance table and one row to UploadedFile, but obviously, I additionally want to map insurance.fileid to uploadedfile.fileid, otherwise I can't fetch a file that is related to insurance. The reason for separating uploadedfile is that it is used by other tables.
The insert is done as following:
Code:
final Insurance insurance=new Insurance();
insurance.setName(name);
final UploadedFile file=new UploadedFile();
file.setFileName(filename);
file.setPath(path);
insurance.setFileId(file);
HibernateCallback callback = new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException, SQLException {
session.save(insurance);
return null;
}
};
hibernateTemplate.execute(callback);
Hibernate sqls:
Code:
Hibernate: insert into UploadedFile (fileId, fileName, path) values (null, ?, ?)
Hibernate: call identity()
Hibernate: insert into Insurance (insuranceId, name) values (null, ?)
Hibernate: call identity()
I am using hibernate version 3.5.0-Final.
Also tried saveOrUpdate() but no success. Any tips would be helpfull. Thanks.