-->
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.  [ 5 posts ] 
Author Message
 Post subject: how to map 2 revisions to each other
PostPosted: Tue Oct 21, 2008 8:37 am 
Newbie

Joined: Tue Oct 21, 2008 7:01 am
Posts: 5
I've implemented a revision framework, to have full history for all changes on a certain object, these revisions references each other, works great for now.

Each revision has a identifier and references to his previous and next revision.

If a identifier has no next revision, this is the latest version.

My application is a resource vs demands scheduler.

So my demands are revisable, and so are my resources.

Now i have to couple them in a many to many relationship, joining them on the identifier, but retrieve only the ones with no next revision.

How schould i do that??


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 03, 2008 5:48 am 
Newbie

Joined: Tue Oct 21, 2008 7:01 am
Posts: 5
Extra INFO, some sample setup how it is now
Code:
<class name="Resource">
<id type="long" name="id" column="resource_id">
   <generator class="increment" />
</id>
<timestamp name="lastUpdateTime" source="db"/>
<property name="identifier"/>
<many-to-one name="previousRevision" class="Resource" cascade="all" lazy="proxy" />
<many-to-one name="nextRevision" class="Resource" />
<bag name="tasks" table="demand_resource">
   <key property-ref="identifier"  column="resource_identifier" unique="false"/>
         <many-to-many class="Demand" unique="false"
            where="nextRevision is NULL" property-ref="identifier" column="demand_identifier"/>
      </bag>
</class>

Code:
<class name="Demand">
<id type="long" name="id" column="demand_id">
   <generator class="increment" />
</id>
<timestamp name="lastUpdateTime" source="db"/>
<property name="identifier"/>
<many-to-one name="previousRevision" class="resource" cascade="all" lazy="proxy" />
<many-to-one name="nextRevision" class="resource" />
<bag name="resources" table="demand_resource">
   <key property-ref="identifier"  column="demand_identifier" unique="false"/>
         <many-to-many class="resources" unique="false"
            where="nextRevision is NULL" property-ref="identifier" column="resource_identifier"/>
      </bag>
</class>


Identifier is a UUID, and the revisions are made by a factory copying al necessary fields. and updating next and previous revision.

This is just a small demo extraction of my real implementation, but the principle is simple like above.

Both work great, but if i want to couple them and save, i get a

Code:
java.lang.NullPointerException
        at org.hibernate.persister.entity.AbstractEntityPersister.loadByUniqueKey(AbstractEntityPersister.java:1677)
        at org.hibernate.type.EntityType.loadByUniqueKey(EntityType.java:641)



Any suggestion


Last edited by xmleke on Thu Dec 04, 2008 5:39 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 03, 2008 5:52 am 
Newbie

Joined: Tue Oct 21, 2008 7:01 am
Posts: 5
sorry duplicate, 2 time commit

Any suggestion


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 03, 2008 1:48 pm 
Beginner
Beginner

Joined: Wed Nov 19, 2008 8:25 am
Posts: 46
Location: Saint Petersburg, Russian Federation
I'm afraid it's not clear what do you want to do. Am I right assuming that you just one to correctly setup many-to-many mapping between Resource and Demand? I.e. 'demand_identifier' table contains mapping between particular Resource and Demand versions?

P.S. please note that your Demand many-to-many mapping points to itself, i.e. target class is Demand. I assume that you intended to use Resource there.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 04, 2008 5:52 am 
Newbie

Joined: Tue Oct 21, 2008 7:01 am
Posts: 5
My mistake, for the misleading info, i edited my previous post.

The problem is that the key of mapping, the identifier is not a unique key

identifier + nextRevision is NULL is unique.

I found a dirty solution by overriding the method "loadByUniqueKey" in
org.hibernate.persister.entity.AbstractEntityPersister.


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

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.