Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Entity class for a View (logical table)

 
Matthew Vahedi
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 543
4
Java Netbeans IDE Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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_
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic