E Armitage wrote:
The JPA solution is really most applicable when you need to do updates and I doubt you'll make those views updatable.
For this I'd execute a native sql query and manually map the data to non entity POJOs.
Bill Gorder wrote:You can do what E Armitage suggested. Alternatively if you do want to define an Entity for the view, JPA requires a primary key for each entity, so in this case you would handle it the same way you would handle a table without a key. James had a link in his Wiki here on it:
http://en.wikibooks.org/wiki/Java_Persistence/Identity_and_Sequencing#No_Primary_Key
If there are multiple columns on the view that do make a row unique you can look at using @IdClass or @EmbeddedId
Bill Gorder wrote:Yeah there is a hibernate specific annotation http://docs.jboss.org/hibernate/orm/3.5/api/org/hibernate/annotations/Immutable.html (make sure to read on this annotation carefully it may not behave exactly as you think it does)
The best way to handle this without vendor specific annotations would probably be to simply make the object immutable.
R. Jain wrote:
So, from this, one workaround is that: -
We make an Id as a primary key.. But how to link it with View??
Jayesh A Lalwani wrote:What's the business key of each of those tables? Apart from the system generated ID, what can be used to uniquely identify the rows?
You need to make sure that your view has the business keys of those tables, and then all the business keys of the dependent tables become the business key of the view. You can treat the business key of the view as the ID.
Bill Gorder wrote:Are you telling me that there is no SQL query that you can write against that view that is guaranteed to return a single result?
R. Jain wrote:By Business key, do you mean Primary key here??)
R. Jain wrote:Well, after some times I found out that, I was getting that exception (Column Index out of Range: 0 < 1) not because I didn't had a column for the primary key in my View..
I was able to fetch a String value from the view (List<String> ) for any one attributes...
But, as and when I try to load Entity object from the Result, it throws an Exception...
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |