-->
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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate property mapping
PostPosted: Sat Dec 10, 2011 10:44 am 
Newbie

Joined: Wed Nov 30, 2011 7:06 am
Posts: 6
Hi All.

I have an object called Checkpoint which is mapped to a DB table using annotations which seems to work ok.

In another table (Patrols) there is some data that I want to get into my Checkpoint objects. I need to get a simple count of how many times a particular checkpoint's ID appears in that table when another column in the Patrols table has a specific value.

The SQL would be something like this:
select count(OID) from PATROLS where checkpoint = 904 and result = 1;

The patrol table is a record of when certain checkpoints have been visited.

The field in Checkpoint would be transient, I have no need to write the data back to the patrol table when storing the checkpoint object.

So I need help working out what the annotation should be, I guess it sounds a bit like a onetomany checkpoint->patrol relationship, but the patrol table doesn't really represent an object as such as far as I can figure (despite the naming). I don't really want to create a patrol object to model that table, but would rather see if it is possible (and then if it is a good idea) to have an annotation something like this in my CHeckpoint class:

@Query(select count(OID) from PATROLS where this.OID = checkpoint and result = 1)
private Integer checkpointHitCount;

I'm hoping that this makes sense to someone.

This isn't a DB I have designed, so I'm still working through how the relationships are supposed to work in this one!


Top
 Profile  
 
 Post subject: Re: Hibernate property mapping
PostPosted: Sat Dec 10, 2011 11:12 am 
Newbie

Joined: Wed Nov 30, 2011 7:06 am
Posts: 6
I think the @formula annotation may hold the key... possibly something like this but not nailed it yet

@Transient
@Formula("(select count(OID) from PATROLS where checkpoint = Checkpoint.OID and result = 1")
private Integer hitCount = 0;
public Integer getHitCount() {return hitCount; }
public void setHitCount(Integer in) {this.hitCount = hitCount; }
:


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.