-->
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.  [ 4 posts ] 
Author Message
 Post subject: What to replace a collection association set of strings with
PostPosted: Wed Dec 28, 2005 1:39 pm 
Beginner
Beginner

Joined: Wed Oct 19, 2005 3:30 pm
Posts: 25
I am replacing a collection association set of strings. I want to return a scholarship object with a set of campus objects rather than the set of campus integers of the campusID. What kind of collection association do I want to replace my set of strings with? One to many, many to one?
(note: I dont need to save any data from the old association, ie: Ill be clearing the database out)

2 tables
scholarships primary key scholarshipID
scholarshipXcampuses primary key campusID

in the scholarshipXcampuses table, one scholarship id currently has several entries(of integers)

scholarshipID campusID
5 1
5 2
5 4
6 2
6 4
7 1
8 2
8 3



Im adding a third table, campuses, which has information about each campus

campuses
campusID campusName ordering
1 East 1
2 Central 2
3 West 3
4 South 4



This is the scholarship mapping file:

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>

<class name="Scholarship" table="scholarship">
<meta attribute="class-description">
A representation of an ASU scholarship
</meta>

<id name="id" column="scholarshipID" unsaved-value="0" >
<meta attribute="scope-set">protected</meta>
<generator class="native"> </generator>
</id>

<property name="name" type="string" not-null="true" column="name"> </property>
<property name="amountType" type="int" not-null="true" column="amount_type"> </property>
<property name="amount" type="int" not-null="true" column="amount"> </property>
<property name="activationDate" type="string" not-null="true" column="activation_date"> </property>
<property name="deadlineDate" type="string" not-null="true" column="deadline_date"> </property>
<property name="openDeadline" type="int" not-null="true" column="open_deadline"> </property>
<property name="applicationUrl" type="string" not-null="true" column="application_url"> </property>
<property name="needBased" type="int" not-null="true" column="need_based"> </property>
<property name="globalList" type="int" not-null="true" column="global_list"> </property>
<property name="minimumGpa" type="int" not-null="true" column="minimum_gpa"> </property>
<property name="minimumHours" type="int" not-null="true" column="minimum_hours"> </property>
<property name="azResident" type="int" not-null="true" column="az_resident"> </property>
<property name="condition" type="text" not-null="true" column="condition"> </property>
<property name="eligibility" type="text" not-null="true" column="eligibility"> </property>
<property name="description" type="text" not-null="true" column="description"> </property>
<property name="comment" type="text" not-null="true" column="comment"> </property>
<property name="contactName" type="string" not-null="true" column="contact_name"> </property>
<property name="contactOrganization" type="string" not-null="true" column="contact_organization"> </property>
<property name="contactPhone" type="string" not-null="true" column="contact_phone"> </property>
<property name="contactEmail" type="string" not-null="true" column="contact_email"> </property>

<set name="campuses" table="scholarshipXcampus" inverse="false" cascade="all" lazy="false">
<meta attribute="field-description">
A scholarship can have many campuses associated with it
</meta>
<key column="scholarshipID" />
<element column="campusID" type="int"/>
</set>
</hibernate-mapping>


This is the campus mapping file:

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

<class name="edu.asu.SFAO.DAOs.Campus" table="campus">
<meta attribute="class-description">
A representation of ASU campuses
</meta>

<id name="id" column="campusID" unsaved-value="0">
<meta attribute="scope-set">protected</meta>
<generator class="native"> </generator>
</id>

<property name="name" type="string" not-null="true"> </property>
<property name="ordering" type="int" not-null="true"> </property>

</class>

</hibernate-mapping>

Hibernate version:
3.1

Name and version of the database you are using:
MS SQL (not sure)


Top
 Profile  
 
 Post subject: Association mappings with join tables.
PostPosted: Thu Dec 29, 2005 1:09 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Have a look in the reference documentation, sections 8.3 and 8.5. They describe exactly what you are looking for.

Assuming that you don't want the campus object to know what scholarships it's in, then you want a unidirectional associaiton mapping with a join table. That's section 8.3. And as one scholarship has many campuses, you want a one-to-many mapping.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 29, 2005 12:16 pm 
Beginner
Beginner

Joined: Wed Oct 19, 2005 3:30 pm
Posts: 25
Im extremely familiar with the docs. One problem I have is I don't know the difference between an association mapping and a collection mapping. Can anyone clear that up?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 29, 2005 1:09 pm 
Beginner
Beginner

Joined: Wed Oct 19, 2005 3:30 pm
Posts: 25
Looking back through the docs again 8.3 and 8.5 dont seem to be related to this problem. They are 8.3. Components as Map indices and 8.5. Dynamic components. However based on your textual description 7.3. Unidirectional associations with join tables seems to be what I want. I implimented scholarship like


<set name="campuses" table="scholarshipXcampus" inverse="false" cascade="all" lazy="false">
<meta attribute="field-description">
A scholarship can have many campuses associated with it
</meta>
<key column="scholarshipID" />
<many-to-many class="edu.asu.SFAO.DAOs.Campus" column="campusID" unique="true"/>
</set>


with no changes to the campus. Im getting the same error I get every time I try to move to an association mapping. When I do a query that should return a result I get something mangled. I have been throwing the result into a list and using it as a jsp as a bean but I always get javax.servlet.ServletException: No getter method for property: "id" of bean: "scholarship". Please check my other thread:

http://forum.hibernate.org/viewtopic.ph ... highlight=


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