-->
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: Select attributes of classes in Hibernate
PostPosted: Fri Feb 27, 2004 6:09 pm 
Newbie

Joined: Fri Feb 27, 2004 5:53 pm
Posts: 3
hi,

I am new to Hibernate, and your help is greatly appreciated.

I am trying to do a join like the following in SQL in Hibernate.

select orgUnit.name, exception.exceptionType
from orgUnit, exception
where orgUnit.code = exception.entityCode

There are two attributes in orgUnit table.
code
name

and three attributes in exception table
code
entityCode
exceptionType

I have created two Data Entities, orgUnit, and exception, and also the hibernate mapping files. But seems Hibernate does not allow me to select attributes from each class. I can select data from each data entity without any problem. But I got an error whenever I tried to select the attributes from each data entity. Can anybody tell me how to do this?

Thanks,

Jane


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 27, 2004 6:47 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
The mappings would be highly useful for us to help you figure out what you should be doing here


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 27, 2004 7:11 pm 
Newbie

Joined: Fri Feb 27, 2004 5:53 pm
Posts: 3
here is my mapping file.

for exception

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class name="org.un.desa.isu.datadirectory.exceptionMgmt.exception" table="exception">
<id name="code" column="code" type="long">
<generator class="increment" />
</id>
<property name="entityCode" type="long"/>
<property name="exceptionType" type="long"/>
</class>

</hibernate-mapping>
<!-- parsed in 0ms -->

for orgUnit

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class name="org.un.desa.isu.datadirectory.orgUnitMgmt.orgUnit" table="orgunit">
<id name="code" column="code" type="long">
<generator class="increment"/>
</id>
<property name="name" type="string"/>
</class>

</hibernate-mapping>

The relation between orgUnit and exception is one-to-many. The entityCode in exception is a foreign key to code in orgUnit. Even if I put the relation mapping to my mapping table, it is not working. So I guess that I would better to remove it and let experts add them to my mapping file.

Thanks,

Jane


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 27, 2004 9:46 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You should map the association, for examples take a look at http://www.gloegl.de/15.html or some other tutorial. Then use a query like this:

Code:
select org.name, exception.type from xxx.Exception exception join exception.orgUnits org


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 01, 2004 11:54 am 
Newbie

Joined: Fri Feb 27, 2004 5:53 pm
Posts: 3
I added the association to my orgUnit mapping as follows:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class name="org.un.desa.isu.datadirectory.orgUnitMgmt.OrgUnit1" table="orgunit1">
<id name="code" column="code" type="long">
<generator class="increment"/>
</id>
<property name="name" type="string"/>
<set name="exceptions" >
<key column="code" />
<one-to-many class="org.un.desa.isu.datadirectory.exceptionMgmt.Exception" />
</set>
</class>

</hibernate-mapping>

Then I tried to do the following as you suggested.

select exception.entityCode, orgunit.name, exception.exceptionType
from exception in class org.un.desa.isu.datadirectory.exceptionMgmt.Exception
join orgunit.code in class org.un.desa.isu.datadirectory.orgUnitMgmt.OrgUnit1 orgunit

I got the error: undefined alias orgunit. Would you please tell me what went wrong and how to fix it in detail?

Thanks,

Jane


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.