farzad wrote:
You might be able to solve this by joins. Look at section 5.1.18 of the online documentation.
Farzad-
Hi, thanks for the reply.
If I use join in the child table's config, then Hibernate will treat is as the parent. The join would need to be used in the mimeTable's config (which is a table i'd rather not map).
In this example A is the child.
create table A (
id integer not null auto_increment,
type integer not null,
primary key (id)
) type=InnoDB;
create table mimeType (
contentTypeId integer not null,
contentType varchar(255),
primary key (contentTypeId)
) type=InnoDB;
alter table A
add index FKTYPE (type),
add constraint FKTYPE
foreign key (type)
references mimeType(contentTypeId);
<class name="A">
<id name="id" type="integer">
<generator class="native"/>
</id>
<join table="mimeType">
<key column="contentTypeId"/>
<property name="contentType"/>
</join>
</class>
public class A {
//...
public void setContentType(String type) {
this.type = type;
}
public String getContentType() {
return type;
}
}
Generates:
[java] Hibernate:
[java] select
[java] a0_.id as id0_0_,
[java] a0_1_.contentType as contentT2_1_0_
[java] from
[java] A a0_
[java] inner join
[java] mimeType a0_1_
[java] on a0_.id=a0_1_.contentTypeId
[java] where
[java] a0_.id=?