-->
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.  [ 11 posts ] 
Author Message
 Post subject: Using interfaces with POJOs and HQL
PostPosted: Mon Sep 05, 2005 2:37 am 
Newbie

Joined: Mon Sep 05, 2005 2:28 am
Posts: 6
Hibernate version: 3.05

Name and version of the database you are using: MySQL

I implement my POJOs with use of interfaces. E.g.

interface Person {
}

class PersonImpl implements Person, Serializable {
}

This force me to use HQL by means of the implementation class, which is natural. E.g. 'from PersonImpl p'.

Does it exist a way to map this so I can make use of the interface instead?
Fx. 'from Person p'

The XxxImpl doesn't look so nice when you have several joined statements.

Cheers,

Ove


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 05, 2005 2:57 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
before posting it is a good thing to actually try the solutions you are asking for..."from Person" works.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 19, 2005 12:47 pm 
Newbie

Joined: Mon Sep 05, 2005 2:28 am
Posts: 6
I forgot to mention I use XDoclet 1.2.3.

As XDoclet tags are annotated in the implementation classes; XDoclet produce a file named XxxImpl.hbm.xml. The side effect of this is that I have to use XxxImpl in my queries.

There is a solution, just add:

<move todir="${maven.build.dir}/classes">
<fileset dir="${maven.build.dir}/classes">
<include name="**/*.hbm.xml"/>
</fileset>
<mapper type="glob" from="*Impl.hbm.xml" to="*.hbm.xml"/>
</move>

after the hibernate-doclet task. Then all files will truncate the Impl-part of the filename.

Cheers,

Ove


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 19, 2005 1:08 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
did you actually try executing "from Person" ? It works..

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 19, 2005 1:12 pm 
Newbie

Joined: Mon Sep 05, 2005 2:28 am
Posts: 6
Yes I did. Like this;

public List getUsers(User user) {
return getHibernateTemplate().find("from PersonImpl u order by upper(u.username)");
}

When i issued Person it failed.

Ove


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 19, 2005 2:36 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
could it be that your class is not named Person but something like my.package.Person ? Then you of course need to tell hibernate about since it is not in the default package as you stated in your postings.

So, either do "from my.package.Person" or use the <import> tag in your hbm.xml e.g. <import class="org.hibernate.test.Person"/>

next time, please post stacktrace or something instead of just say it errors....thank you

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 19, 2005 8:47 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Max means the interface is not named Person. And he is exactly right. You need to add an explicit <import>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 20, 2005 1:10 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
argh - where is the semantical spellchekker when i need one...

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 20, 2005 2:45 am 
Newbie

Joined: Mon Sep 05, 2005 2:28 am
Posts: 6
My project is getting quite sized and with lot's of dependencies. Right now my sources are broken due to refactoring... I check out the the <import> when I'm up again.

Thanks a lot for your inputs!

Cheers,
Ove


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 28, 2005 9:50 am 
Newbie

Joined: Wed Sep 21, 2005 1:13 am
Posts: 5
max wrote:
could it be that your class is not named Person but something like my.package.Person ? Then you of course need to tell hibernate about since it is not in the default package as you stated in your postings.

So, either do "from my.package.Person" or use the <import> tag in your hbm.xml e.g. <import class="org.hibernate.test.Person"/>


This will only work if the interface Parent is also annotated/mapped ?

I have been trying this with annotations, trying to keep my interface clear of any persistence annotation, and "from my.package.Person" does not seem to work in this case. Have I missed something ?

thanks
davidv


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 28, 2005 10:03 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
it should work without any annotations afaik...

_________________
Max
Don't forget to rate


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