I have a view over three tables. It has 6 columns as follows:
ID | NAME | PRINCIPAL_ID | DESCRIPTION | GROUP_ID | TYPE
As I’m using hibernate to retrieve data from database, I had to put the ID column in this view. The problem is, I cannot generate a unique ID which seems to be necessary for hibernate to correctly load the data.
How can I have a unique ID for every row in this view?
Maybe this can help, I’m not sure: The combination of PRINCIPAL_ID and GROUP_ID can make a unique ID. All these three are Long.
UPDATE: When you insist to have it as a number, create your view like this:
But that’s really it – no more other possibilities. Cast rownumber as
longlike I said in comments, if it really, really has to belong.Alternatively in a procedure:
Then get result with
Original answer:
From the MySQL manual:
UUID()
Another way would be to use
CONCAT()to build your unique ID.