This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Entity class for a View (logical table) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Entity class for a View (logical table)" Watch "Entity class for a View (logical table)" New topic
Author

Entity class for a View (logical table)

Matthew Vahedi
Greenhorn

Joined: Jan 05, 2012
Posts: 16
Hi everybody,

Thanks for answering my previous question, those are great answers and helped a lot.

Now..

I have got a View that fetches it's result from different tables. There is no primary key in this View. I'm using Hibernate JPA for the rest of my Oracle tables.

Questions:

1- Can I create an Entity class for this View? ( What should I do for the lack of primary key? )

2- Where can I place the SQL ( not JPQL ) command that creates this View? My guess is inside DAO class but not sure how and what API must be used?

Thanks in advance.

Cheers,
Dieter Quickfend
Bartender

Joined: Aug 06, 2010
Posts: 543
    
    4

There are several options which you can use, among which:

- Add (a) column(s) to your view which is eligible as a PK, and use that as a PK for your entity. It doesn't have to be a PK in the database.

- define a composite primary key in your entities. You can define a primary key composed of all columns in your entity if completely duplicate entities do not exist. If you can find a number of columns which will never have the same value more than once, create your composite key. It doesn't have to be a PK in the database.

- If you don't need your entity to be managed, you can use Result Classes Constructor Expression. I think this is probably the best solution for your problem, but I am not in a position to decide whether or not you need your entities managed. This case has the lowest footprint, of course. See here: http://www.objectdb.com/java/jpa/query/jpql/select#Result_Classes_Constructor_Expressions_


Oracle Certified Professional: Java SE 6 Programmer && Oracle Certified Expert: (JEE 6 Web Component Developer && JEE 6 EJB Developer)
 
GeeCON Prague 2014
 
subject: Entity class for a View (logical table)