-->
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: How to Mapp vectors
PostPosted: Thu Nov 03, 2005 2:37 pm 
Newbie

Joined: Thu Oct 06, 2005 9:30 am
Posts: 18
Location: Canada
I have the following two classes

public class A {
private int id;
private String name;
private String result;
private Vector list;

public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getListCount(){
return this.list.size();
}
public B getList(int index){
B b = (B)list.elementAt(index);

return b;
}
public void addList(B b) {
this.list.add(b);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getResult() {
return result;
}
public void setResult(String result) {
this.result = result;
}
}

*********************************
public class B {
int id;
String name;
String time;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
}
*************************************
My mapping file for A.hbm.xml. is as follows

<hibernate-mapping >
<class name="A" table="A">
<id name="id" type="int" column="Id">
<generator class="increment" />
</id>

<property name="name" />
<property name="resul" />

I am not sure how to map my variable "list" here. Also a list has many objects of B class. Need some help here.

</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 03, 2005 3:14 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
Code:
    <list
        name="listAttributeNameinClassA"
        //put more options here to customize relationship

    >
        <key>
            <column name="id" />
            // more here if needed


        </key>
        <index column="some_index" />
        <one-to-many
            class="package.B"
        />
    </list>




also you'll need an attribute in Class A that stores the List and has getters and setters which will have the name matching, for the above example, listAttributeNameinClassA

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 03, 2005 4:03 pm 
Newbie

Joined: Thu Oct 06, 2005 9:30 am
Posts: 18
Location: Canada
I already have "Vector list;" that stores objects of Class B. Do I need to have another List that stores "Vector list". Confused..


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 03, 2005 4:47 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
I don't think Hibernate directly supports building Vectors from its source code. It returns Interface implementations, like List and Set and Bag.

What you need to have in Class A is something like

Code:
Class A {

int someid;
List collectionB;
...

public void setCollectionB(List collectionB) {
this.collectionB = collectionB;
}

public List getCollectionB() {
return this.collectionB;
}


and then the mappings i provided in the first post to implement this in hibernate

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


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.