I have a relationship between two objects which is someone difficult.
One object DBFunctionConnection has a relationship to another object DBCircuit. Like so.
Code:
public final class DBFunctionConnection implements IDSFunctionConnection, Serializable, Cloneable{
/**
*
*/
private static final long serialVersionUID = 1L;
/*
* Hibernate spec version 3.2.0.ga section 4.1.2 states that transitive
* reattachment of detached objects requires an identifier. So we have one.
*/
private Long id; // identifier
//private DBCircuit circuit;
private Long circuit;
}
The issue is, DBFunctionConnection is serialized but DBCircuit is not and can not and should not be made to serialize, due to other application requirements. Thus, while I normally would have DBFunctionConnection contain DBCircuit, I have taken to instead of DBFunctionConnection contain a Long which is the id of the circuit in question.
However, I have accomplished this through trickery. My DDL hbm.xml file for DBFunctionConnection is like so;
Code:
<hibernate-mapping>
<class name="com.rgdsft.hib.core.DBFunctionConnection" table="dbfunctionconnection" lazy="false">
<id name="id" type="long">
<generator class="native"/>
</id>
<!-- this is for DDL only -->
<many-to-one name="circuit" class="com.rgdsft.hib.core.DBCircuit" column="circuitid" access="field" lazy="false" not-null="false"/>
</class>
</hibernate-mapping>
But the xml file I use for runtime is like so;
Code:
<hibernate-mapping>
<class name="com.rgdsft.hib.core.DBFunctionConnection" table="dbfunctionconnection" lazy="false">
<id name="id" type="long">
<generator class="native"/>
</id>
<property name="circuit" column="circuitid" access="field" type="long"/>
</class>
</hibernate-mapping>
Almost the same but I have changed the many-to-one relationship normally there for a simple property at runtime. This has worked for quite a while. I think it should work as hibernate does not care about much if the db format matches the hbm.xml definition.
But lately I have started to get another error which research showed typically came from mapping vs. class mixups.
Failed to execute transaction
org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of com.rgdsft.hib.core.DBObject.id
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:171)
Personally, my mapping does match my class so I am skeptical if that is my issue. Anyway, the question for this post, is there a better way to accomplish what I am trying here!?