-->
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.  [ 8 posts ] 
Author Message
 Post subject: How to save this type of data ?
PostPosted: Mon Jan 12, 2004 11:32 pm 
Beginner
Beginner

Joined: Thu Sep 04, 2003 2:52 am
Posts: 29
HI all,
I have a problem in saving data using hibernate.

I have a data class:

Code:
class Data {
  Value value;
}

class Value {
  List values;//[b] this list in turn contains a list ,which contains real data[/b]}


Now ,I have to save the Data,how can I do this ? anyone can help me ?

cowrie


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 12, 2004 11:36 pm 
Beginner
Beginner

Joined: Thu Sep 04, 2003 2:52 am
Posts: 29
Actually this is a problem in saving a two dimensional array data type.


Top
 Profile  
 
 Post subject: Re: How to save this type of data ?
PostPosted: Tue Jan 13, 2004 1:49 am 
Newbie

Joined: Thu Sep 18, 2003 1:50 am
Posts: 17
Here is the mapping for that,

<?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="com.abcd.Value" table="value">
<id name="id" type="int" unsaved-value="0">
<generator class="identity"/>
</id>
<bag name="values">
<key column="value_id"/>
<one-to-many class="com.abcd.Value"/>
</bag>
</class>

<class name="com.translogicsys.persistence.Data" table="data">
<id name="id" type="int" unsaved-value="0">
<generator class="identity"/>
</id>
<many-to-one name="value" class="com.abcd.Value"/>
</class>
</hibernate-mapping>

- Jeevan (G1)
-------------------------------------------------------
vipcowrie wrote:
HI all,
I have a problem in saving data using hibernate.

I have a data class:

Code:
class Data {
  Value value;
}

class Value {
  List values;//[b] this list in turn contains a list ,which contains real data[/b]}


Now ,I have to save the Data,how can I do this ? anyone can help me ?

cowrie


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 13, 2004 2:54 am 
Beginner
Beginner

Joined: Thu Sep 04, 2003 2:52 am
Posts: 29
class Result {
RequestResult[] results;
}

class RequestResult {
List requestResultObjs; //// This List is really a table ,
//// Its row is a list
//// its cell is all of type: RequestResultObj
}

class RequestResultObj {
Value value;
}

class Value {
int i;
String desc;
}

I must store Result. It's challeging,isn't it? who can solve this problem?


Top
 Profile  
 
 Post subject: Re:
PostPosted: Tue Jan 13, 2004 3:42 am 
Newbie

Joined: Thu Sep 18, 2003 1:50 am
Posts: 17
Here is my solution to the problem statement you've given:

<?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="com.abcd.Request" table="request">
<id name="id" type="int" unsaved-value="0">
<generator class="identity"/>
</id>
<array name="results">
<key column="request_id"/>
<index column="resultindex" type="int" />
<one-to-many class="com.abcd.RequestResult" />
</array>
</class>
<class name="com.abcd.RequestResult" table="requestresult">
<id name="id" type="int" unsaved-value="0">
<generator class="identity"/>
</id>
<list name="requestResultObjs">
<key column="requestresult_id"/>
<index column="objindex" type="int" />
<one-to-many class="com.abcd.RequestResultObject" />
</list>
</class>
<class name="com.abcd.RequestResult" table="requestresult">
<id name="id" type="int" unsaved-value="0">
<generator class="identity"/>
</id>
<list name="requestResultObjs">
<key column="requestresult_id"/>
<index column="objindex" type="int" />
<one-to-many class="com.abcd.RequestResultObject" />
</list>
</class>
<class name="com.abcd.RequestResultObject" table="requestresultobject">
<id name="id" type="int" unsaved-value="0">
<generator class="identity"/>
</id>
<many-to-one name="value" class="com.abcd.Value"/>
</class>
</hibernate-mapping>

As I'm new to Hibernate, I'm trying to learn it with the help of this forum. Anybody who has time, please validate the solution.

Thanks,

- Jeevan (G1)

********************************************************
vipcowrie wrote:
class Result {
RequestResult[] results;
}

class RequestResult {
List requestResultObjs; //// This List is really a table ,
//// Its row is a list
//// its cell is all of type: RequestResultObj
}

class RequestResultObj {
Value value;
}

class Value {
int i;
String desc;
}

I must store Result. It's challeging,isn't it? who can solve this problem?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 13, 2004 3:56 am 
Beginner
Beginner

Joined: Thu Sep 04, 2003 2:52 am
Posts: 29
thanks , I am surprised that you are just a newer to hibernate. I would test your solutions in my project. But I think it's ok.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 13, 2004 9:41 pm 
Beginner
Beginner

Joined: Thu Sep 04, 2003 2:52 am
Posts: 29
I have test this mapping,but I've got some exceptions.such as follows:
----------------------------


net.sf.hibernate.MappingException: No persister for: java.util.ArrayList

the code is :
Code:
    RequestResult rrTable = new RequestResult();
    rrTable.addRRO(rro1);
    rrTable.addRRO(rro2);
    rrTable.addRRO(rro3);
    rrTable.addRRO(rro4);
    rrTable.addRRO(rro5);
    List requestResultList = new ArrayList();
    requestResultList.add(rrTable);

    pr.setRequestResult(requestResultList);
    try {
      pdao.insertPollingResult(pr);
    }
    catch (HibernateException ex) {
      ex.printStackTrace();
    }


Top
 Profile  
 
 Post subject: Re:
PostPosted: Wed Jan 14, 2004 1:01 am 
Newbie

Joined: Thu Sep 18, 2003 1:50 am
Posts: 17
The reason for the exception is in one of the collections you're trying to save contains objects of type ArrayList. That ie, that collection is again contains a collection ArrayList which is not known to Hibernate. The reason could be:

- either the requestResult property in the class related to "pr" is ArrayList
- or atleast on of the rro* series of objects is of type ArrayList.

- Jeevan (G1)

_________________
- Jeevan (G1)


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