Hibernate version: 3.1.1
Name and version of the database you are using: MySQL 5 (soon to be Oracle 10g)
Hello All!
I have a object model where I am putting chunks of data into clob fields in the backing database, with multiple clobs (6 in one case) on one table.
My DBA is pushing me to put these clobs into a seperate table, effectively making a row for each clob column, and mapping them back into my object. This would not be so bad, except that the clobs are at different levels in my mapping: I have (at times) components inside components, where all of them, including the entity class, might have a clob field.
Here is a quick example:
Code:
public class A {
private String clob1;
private B b_obj;
... getters and setters
}
public class B {
private String clob2;
... getters and setters
}
current hbm mappings:
Code:
<hibernate-mapping>
<class name="A" table="table_a">
<id name="id" type="java.lang.Long" unsaved-value="-1">
<column name="id" />
<generator class="native" />
</id>
<component name="b_obj" class="B">
<property name="clob2" type="java.lang.String">
<column name="clob2"/>
</property>
</component>
<property name="clob1" type="java.lang.String">
<column name="clob1"/>
</property>
...
</class>
</hibernate-mapping>
My first question is:
has anyone else done this? if so can you describe your solution?My initial reaction was to create a HashMap inside my model's base classes, and just code the getters and setters at each level to be pass the data between the caller and the mapm, using a unique map key for each particular field. This works, except that for the mapping, each level needs to know about the Entity relationship between the main table and the clob table.
As far as I can tell, each component class needs to know who it's parent is, or the parent has to tell the component class that it (the parent) is the parent for that component. I do not particularly like this from an OO perspective.
Which brings me to my main question:
Is there a way for component classes to "know" in the hbm mapping what the id is for that entity?If so, then I think all can be right in the world again, as I could potentially use a better relationship than the map (hopefully one-to-one for each clob field). Otherwise anyone know why that is not allowed? It is really just a mapping issue, and the hbm already knows the internals of the component.
Here is some sample code to further explain:
Code:
public class EntityBase{
private Map extensions = new HashMap();
private EntityBase parent = null;
.. getters and setters
}
public class A extends EntityBase {
private String clob1;
private B b_obj;
... getters and setters
public String getClob1() {
return (String) this.getExtensions.get("CLOB1")
}
public void setBObj(B obj) {
this.b_obj = obj;
this.b_obj.setParent(this);
}
}
public class B {
private String clob2;
... getters and setters
}
current hbm mappings:
Code:
<hibernate-mapping>
<class name="A" table="table_a">
<id name="id" type="java.lang.Long" unsaved-value="-1">
<column name="id" />
<generator class="native" />
</id>
<component name="b_obj" class="B">
</component>
...
<!-- new clob mapping -->
<map name="extensions" table="clobs" cascade="all" lazy="false">
<key column="id"/>
<map-key column="field" type="string"/>
<element column="clob" type="string"/>
</map>
</class>
</hibernate-mapping>
Thanks very much in advance!