-->
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.  [ 3 posts ] 
Author Message
 Post subject: Parameterized forumla attribute
PostPosted: Tue Jan 11, 2005 10:54 am 
Newbie

Joined: Tue Nov 02, 2004 9:15 am
Posts: 5
Hibernate version: 2.1.7

Mapping documents:

Code between sessionFactory.openSession() and session.close(): N/A

Name and version of the database you are using: Oracle 9.2.0.5


Hello all,

I have a class that I am persisting in a table, and I have added some attributes that are calculated via a stored procedure in the database using the formula attribute.

This works fine, except in my more complex cases where some of the parameters to the stored procedure are not available from properties of the class itself. I would like to be able to pass them in as parameters to my query. But it appears that Hibernate does not see them as parameters.

For example:
Code:
<property ... formula="my.function(prop1,  :param1, :param2)" />


and:

Code:
Query q = s.createQuery("FROM blah");
q.setParameter("param1", "x");    // IllegalArgumentException: Parameter param1 does not exist as a named parameter in []
q.setParameter("param2", "y");

Collection rs = q.list();



Apart from resorting to a native SQL query (which I am not 100% will work), is there someway to achieve what I want?

Thanks in advance for any help,
David Sykes


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 08, 2006 6:33 am 
Newbie

Joined: Wed Nov 08, 2006 6:17 am
Posts: 5
Maybe not the correct forum, but I'll just kick this topic, as it is exactly what I'm looking for: named parameters in calculated properties. Are there any updates on this?

Me myself, I'm using NHibernate 1.0.2.0 on Sql Server 2000.


Top
 Profile  
 
 Post subject: We solves the issues using views
PostPosted: Wed Nov 08, 2006 9:04 pm 
Newbie

Joined: Tue Nov 02, 2004 9:15 am
Posts: 5
Hi Grimace,

I never received an answer to my original query, so in the end we solved the problem using views.

So, let's say that I have table A, with columns A,B,C. When I select from this table I want to also retrieve the result of calling function F.

Now, I can get the values for function F from the columns of table A, and from the columns of table B, which are D,E,G.

So I create a view:

CREATE VIEW v AS
SELECT a.a., a.b, a.c, b.g, f(a.c, b.d, b.e) f
FROM a, b;

I then map v to a class using hibernate, and set it as read-only. To query from v I need to make sure that I define a condition for B.G, otherwise I end up with a cartesian join.

This has worked very well for us. The obvious downside is that you need to map to two different classes if you need to also write records to table a.

I hope that helps you out,
Dave


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