-->
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.  [ 3 posts ] 
Author Message
 Post subject: Two design problems..
PostPosted: Tue Mar 24, 2009 2:39 pm 
Newbie

Joined: Tue Mar 24, 2009 2:26 pm
Posts: 1
Hi

I use Hibernate 3 with annotations and I have two design problems I have trouble finding the answer to..

First:
I would like to map a collection (private Map<String, String> whatever) which does not correspond to any whatever class, what is the best way to do this? Im using annotations and would appreciate a code example.


Second:
I have a BaseEntity class in which I would like to have "Date createdDate" and "Date lastUpdated" what is the best way to do this. I have tried using a listener but could only get it to work on creation date but I would if possible like to use a simpler solution. Again a code example using annotations would be appreciated.



Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 25, 2009 5:02 pm 
Senior
Senior

Joined: Tue Aug 01, 2006 9:24 pm
Posts: 120
Code:
First:
I would like to map a collection (private Map<String, String> whatever) which does not correspond to any whatever class, what is the best way to do this? Im using annotations and would appreciate a code example.

What do you mean by this (what is the collection for)?

If it's not for persisting any data you can just use the @Transient annotation

Code:
Second:
I have a BaseEntity class in which I would like to have "Date createdDate" and "Date lastUpdated" what is the best way to do this. I have tried using a listener but could only get it to work on creation date but I would if possible like to use a simpler solution. Again a code example using annotations would be appreciated.


The listener seems like the best solution.

However in the past I have implemented an interface on all of my entities. And used a manager layer that would always pass my entities to methods in a superclass that all my managers extended. This only works when you are starting from scratch and your persisting one class at a time.

I would be interested in any other solutions to this problem also.

_________________
Please rate my replies as I need points for all of my questions also.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 25, 2009 5:24 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Quote:
I would like to map a collection (private Map<String, String> whatever) which does not correspond to any whatever class, what is the best way to do this? Im using annotations and would appreciate a code example.


You'll need to use the Hibernate extended annotation for this since it is not possible with standard JPA annotations. Check http://www.hibernate.org/hib_docs/annot ... -extratype for a (somewhat complex) example. It should be possible to use a Map<String, String> also. There are more examples in the documentation for xml-based configuration: http://www.hibernate.org/hib_docs/v3/re ... s-ofvalues


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.