-->
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: Read only Objects, Dont need to persist id
PostPosted: Wed May 16, 2007 8:23 pm 
Newbie

Joined: Wed May 16, 2007 7:33 pm
Posts: 3
Hibernate version: 3.2

I have lot of data in the database which is updated thru some different process(Not Hibernate). In UI(where I'm using Hibernate), I just need to read and show this data. I dont need to persist this data from UI. All I need is to display it in UI. This data is stored in legacy database with legacy schema. Some of the data is read from "database view" which is like a table for hibernate. These database views do not have a primary key. As this is read only data, the query or view does not need to have a primary key. Now, I need to map this view to a class which does not have primary key. But hibernate requires either primary key or composite key or natural key.

I'm newbie to hibernate and I tried searching around different forums and googling. But didnt find any solution.

So my question is, Is it possible to have id created in hibernate which is set in java class (POJO), but not persisted in the database. By this POJO's can be uniquely identified in the application and also does not require to be persisted as this is ready only data.

Any suggestions how I can do this? Is there somewhere I can tell that this class is read only and does not need to persist in database, so that hibernate can create id only in POJOs and not store it in table.

Thanks for your help,
Shailendra


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 17, 2007 12:33 am 
Senior
Senior

Joined: Sat Aug 19, 2006 6:31 pm
Posts: 139
Obviously this needs further testing but I've managed to get around it by choosing one column in the view and using it as the ID (mapping it in the mapping file or use the @Id annotation if you use annotations).

In the limited testing that I do I was able to get data out of the view.

_________________
Don't forget to rate the reply if it helps..:)

Budyanto


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 17, 2007 12:53 am 
Newbie

Joined: Wed May 16, 2007 7:33 pm
Posts: 3
Yes you can do that. But you wont get unique id if the result set contains multiple values for that column in the view. So in application if I want to refer to a particular object, I wont be able to uniquely find that object by its id because it is mapped to a column which has multiple values.

Ideally, it would be good to have id in the object which is uniquely created by hibernate which it does, but not associate it with the column of the table. As we dont want to store it in the table (because it is a view).


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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.