-->
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: Using Formula with non "basic" type
PostPosted: Wed Mar 08, 2006 9:24 pm 
Newbie

Joined: Wed Mar 08, 2006 9:10 pm
Posts: 7
Hibernate version: 3.1.2

Full stack trace of any exception that occurs:
Caused by: org.hibernate.MappingException: Could not determine type for: de.innovalan.jpelas.domain.impl.User, for columns: [org.hibernate.mapping.Formula( (SELECT p.created_by FROM Post p, Thread t WHERE p.thread_id = thread_id ORDER BY p.created_at DESC LIMIT 1) )]
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:266)
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:253)
at org.hibernate.mapping.Property.isValid(Property.java:185)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:395)
...

In the Entity "Post" the property "createdBy" of type "User" is mapped to "created_by". The primary key of "User" is an int.

I'm trying to use a Formula for a field in a Class "Thread":
@Formula("(SELECT p.created_by FROM Post p, Thread t WHERE p.thread_id = thread_id ORDER BY p.created_at DESC LIMIT 1)")
private User lastPostBy;

This should give me the User that created the Post that has the highest value in "created_at".

I even tried
@Formula("FROM User u where u.user_id = (SELECT p.created_by FROM Post p, Thread t WHERE p.thread_id = thread_id ORDER BY p.created_at DESC LIMIT 1)")
with no success.

Is mapping with Formulas only available to "build-in basic"-types? Or am I missing the clue to how to use it with custom types?

Thanks in advance!

Sven

PS: "User" is mapped properly as I can load it with the Sessions load()-method.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 09, 2006 9:55 am 
Newbie

Joined: Wed Mar 08, 2006 9:10 pm
Posts: 7
I found out that I would have to use @ManyToOne with this. But many-to-one can only be configured to use a formula when configuring via mapping.xml-configfile, as @ManyToOne does not support @Formula. See here: http://opensource2.atlassian.com/projec ... se/ANN-210
Is there any known workaround?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 09, 2006 9:58 am 
Newbie

Joined: Wed Mar 08, 2006 9:10 pm
Posts: 7
I just found out, that this thread is a dupe to: http://forum.hibernate.org/viewtopic.php?t=953425

Just ignore this. :)


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.