-->
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.  [ 7 posts ] 
Author Message
 Post subject: how to persist object containing org.dom4j.Document
PostPosted: Thu May 27, 2004 5:09 pm 
Beginner
Beginner

Joined: Thu Apr 15, 2004 5:12 pm
Posts: 21
What is the easiest way to persist an object containing a org.dom4j.Document as a field? What I have been doing so far is writing a table for every class I want to persist, but they were all classes I created.

To make it concrete, suppose I want to persist the following:

Code:
public class DocumentWrapper {
  String                       id;
  org.dom4j.Document doc;

  public String getId() { return id; }
  public void setId(String id) { this.id = id; }
  public org.dom4j.Document getDoc() { return doc; }
  public void setDoc(org.dom4j.Document doc) { this.doc = doc; }
}


The class entry in my mapping file would be something like the following:

Code:
<class table="DocumentWrappers" name="DocumentWrapper">
  <id type="string" name="id">
    <column not-null="true" sql-type="char" name="ID" length="32"/>
    <generator class="assigned"/>
  </id>
  <property name="doc" type="org.dom4j.Document">
    <column sql-type="??" name="DOC" not-null="true"/>
  </property>
</class>


What would the sql-type be? And do I also need a class element for the org.dom4j.Document class?

This is probably a really simple question, but I'm not seeing how to handle this. Thanks for any help.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 28, 2004 3:49 am 
Regular
Regular

Joined: Wed May 12, 2004 3:03 am
Posts: 51
Location: France
Hi,

When the type of an attribute of an object is also an object, you have to map it like an association. So, you write a one-to-one association, a one-to-many or a many-to-many association, and it is the same for a class like org.dom4j.Document.

Don't forget you must have a mapping file for all the class you map, so you need one for the Document class.

Bye,

Charles


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 28, 2004 4:42 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Depends on how you want to store it, if you just want to put all the XML into a varchar field, a custom UserType would be the easiest.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 28, 2004 5:35 pm 
Beginner
Beginner

Joined: Thu Apr 15, 2004 5:12 pm
Posts: 21
michael wrote:
Depends on how you want to store it, if you just want to put all the XML into a varchar field, a custom UserType would be the easiest.


Thanks for the response. It isn't a string, so I don't think I can put it into a varchar field, unless you mean changing the doc field so it's a string instead of a Document. That is not a good solution though, because I don't want to deal with strings but with Document objects.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 28, 2004 5:38 pm 
Beginner
Beginner

Joined: Thu Apr 15, 2004 5:12 pm
Posts: 21
_charles_ wrote:
Hi,

When the type of an attribute of an object is also an object, you have to map it like an association. So, you write a one-to-one association, a one-to-many or a many-to-many association, and it is the same for a class like org.dom4j.Document.

Don't forget you must have a mapping file for all the class you map, so you need one for the Document class.

Bye,

Charles


hi Charles,

Thanks for the response. What I don't understand though is that if it is necessary for me to write a mapping for the org.dom4j.Document class, what would, for example, the id be? I don't quite understand how pre-written classes designed by somebody else would be mapped, since I don't have access to the internals, in general, and they won't necessarily have a field that I could use as the id.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 28, 2004 5:51 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Of course it is possible to persist the Document object into a string field - read the docs how UserTypes work. It all depends on how you want to store the XML in the database, probably you could tell us that?


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 28, 2004 6:38 pm 
Beginner
Beginner

Joined: Thu Apr 15, 2004 5:12 pm
Posts: 21
michael wrote:
Of course it is possible to persist the Document object into a string field - read the docs how UserTypes work. It all depends on how you want to store the XML in the database, probably you could tell us that?


Thanks. I will look into UserTypes. I don't care how the XML is stored. I just want to persist an object that has a Document as a field, and be able to get back an object from the database such that when I call getDoc(), it returns an equivalent Document object. The quickest, easiest route to that end is what I want, which looks like a UserType at this point, but there are no other constraints, so if there is an easier way...


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