-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Relating on ID as opposed to class/object
PostPosted: Wed Jul 04, 2007 10:04 am 
Newbie

Joined: Wed Jul 04, 2007 9:45 am
Posts: 1
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!?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.