This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Can you map to a view in the same way as a table? What happens if the view does not contain a primary key? When I do a select statement based on a person's id I don't get all the results in my result list. My result size is correct but it only returns the first record. Is this what happens when mapping with hibernate in this circumstances?
Any Suggestions? Should I be looking at composite-ids would this fix it?
If you don't have PK, which column is the ID? You have to make sure that the field(s) that you have marked as Id in the entity uniquely identify the record, and are non-nullable.
Joined: Feb 10, 2009
Yeah, that's the problem. While there are no null values all the fields in the view are nullable. But, theoretically, if I do a select query on this read-only view based on a person's id I should get a list of records for the user. However, when I run the query below I get the correct number of records but they are outputting the same exact record repeatedly instead of distinct records.
I have been doing a search on this for the past few days and I'm running out of ideas. There are no static variables in my domain class, running the sql stmt gives me the correct results when running it against the database, so I'm left wondering if this is a hibernate mapping problem. I'm scraping the bottom of the bucket on this one and I'm trying to leave no stone unturned but I'm not finding anything that stands out. Below if my query and mapping (I tried using id and composite id without any luck)
If personid is not unique, you will not get all the records. The ID field has to uniquely identify the record. It doesn't have to be the PK (although making PK the Id field guarantees uniqueness), but it does have to be unique.
What you need to do is identify the business keys of your underlying tables, and make sure that the business keys of the underlying tables are included in the view. The combination of the business keys of the underlying tables will be the business key of the view. You need to make the business key columns as the ID.
Joined: Feb 10, 2009
Well does it make it easier that it's only one table(view) that I'm working with?
Can I fake this through the hibernate mapping? Or do I need to modify the actual table, because I don't have permissions to the database to modify it.
Is it possible for me to use the composite key attribute to group personid and requirement since it creates a unique key? Is that what you are meaning?