-->
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.  [ 6 posts ] 
Author Message
 Post subject: Can Hibernate create plain POJO's with std java collections
PostPosted: Mon May 23, 2005 12:48 pm 
Newbie

Joined: Mon May 23, 2005 12:40 pm
Posts: 3
I have a situation where I would like to use Hibernate to read objects from a database with no requirement to ever write them back. Furthermore, it would be helpful if the resulting objects were based on the standard java collection classes, with no Hibernate classes present in the resulting data structures.

Is this possible, or must I do a manual copy from one form to the other?

Many thanks for any advice.

AD[/b]


Top
 Profile  
 
 Post subject: Re: Can Hibernate create plain POJO's with std java collecti
PostPosted: Mon May 23, 2005 2:30 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
AndyD wrote:
I have a situation where I would like to use Hibernate to read objects from a database with no requirement to ever write them back. Furthermore, it would be helpful if the resulting objects were based on the standard java collection classes, with no Hibernate classes present in the resulting data structures.

Is this possible, or must I do a manual copy from one form to the other?

Many thanks for any advice.

AD[/b]


If you don't want to write them back, you can specify mutable=false which tells hibernate that they're read only.

Why do you care what the underlying implementation of the Collections are since it's best practice to code to interfaces and Hibernate provides data in java.util.Set, java.util.List collections etc...


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 23, 2005 3:17 pm 
Newbie

Joined: Mon May 23, 2005 12:40 pm
Posts: 3
Two main reasons (largely related to serialisation):

1) I want to be able to save them as XML files, using something like Castor, and it'd be easier to use the standard mappings 'out of the box'.

2) Ditto for serialisation in the context of a distributed cache.

I know that I can overcome this issue by writing my own mappings/serializers but I'm just lazy by nature ;-)


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 23, 2005 3:28 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
AndyD wrote:
Two main reasons (largely related to serialisation):

1) I want to be able to save them as XML files, using something like Castor, and it'd be easier to use the standard mappings 'out of the box'.

2) Ditto for serialisation in the context of a distributed cache.

I know that I can overcome this issue by writing my own mappings/serializers but I'm just lazy by nature ;-)


I'm not that familiar with Castor but it's hard for me to believe that it expects your Collections to be concrete classes (java.util.ArrayList, HashMap etc...) and not interfaces (java.util.List, Map, Collection etc...)

Hibernate also has built-in support for a variety of Cache implementations.


Top
 Profile  
 
 Post subject: but...
PostPosted: Tue May 24, 2005 3:13 am 
Newbie

Joined: Mon May 23, 2005 12:40 pm
Posts: 3
Castor is quite capable of serialising most standard beans. However, it expects to deserialise them into the same classes that it started from (it stores the class details as part of its serialision data). However, it is probably unacceptable for the deserialisation to create internal Hiberate classes - especially if this is done outside of a session, as might possibly be the case.

In the case of a distributed cache, the situation is even more extreme, since the remote cache instance on which the object is re-formed might not even have Hibernate installed.

I'm assuming from your response that my request is not supported, so I guess I'll have to write my own mappings & serialiser. Thanks for all your help in any case.

Regards,

AD


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 24, 2005 6:58 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
did you take a look at H3 xml support ? it might be enough for you so you dont need to use yet another tool ,)

_________________
Max
Don't forget to rate


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