And I was wondering if I want Hibernate to crate the database table and name it and the columns, at the same time I want the primary key to be a hash value (as a String) that I generate at run time.
would something like the answer for the above question work?
thanks for looking,
So the values I’m starting with are:
A unique string
The hash value of the string, but String.valueOf(str.hashCode())
the hash is generated at runtime and converted to a string
So when I run the application for the first time, I want Hibernate to start off creating the table and the columns,
define the primary key to be the string hash value.
What annotations do I need to add to the entity to achieve that?
Ok, just to be sure, the link describes how to achieve the following?
When I first run the app, new (blank) database Hibernate will have a table built (according to the annotations in the entity) the table would get a column id and a column item
Table Items
| ID (varchar) | ITEM (varchar) |
and then I can populate the table with the string and the string hash as the ID, as follows:
| ID (varchar) | ITEM (varchar) |
| 8765456 | item number 1 |
…
| 5678987 | item number 2 |
…
| 3976563 | item number 3 |
…
| | |
I told you how to build a column name dynamically.
So when I run the application for the first time, I want Hibernate to start off creating the table and the columns, define the primary key to be the string hash value.
Now, you are telling that the column name is static and the values are assigned with some hashes.
If that’s the case, then just use an assigned identifier and set the id with the calculated hashValue.