This has always been an annoyance with Hibernate / JPA and now trying to see if there is a way around this limitation.
Basically given a Store and User ... say a Store has many users.
I prefer Store declared manually in a Store table, and users in a User table. The connection is in a StoreUser table.
You repeat this for a number of this, StoreAddress, StoreEmployee and so on and you have a bunch of things.
However, for the common case of getting everything related to a Store, and getting the users, addresses and what not, JPA forces you to create a Store Entity that contains all these things.
StoreBond {
List<Address> address
List<User> users
....
}
My intention is just to user this for query, never to insert so I don't need a table for it.
My intention is to be able to build Hibernate criteria queries and map the associations to do so. Criteria queries can be quite powerful to filter on things.
But I do not want an empty table in my sql schema since it won't do anything anyway, I also don't want this class to have anything to do with the model other than mapping to it results from the database.
Is there a way around this limitation.
To have a connection/bond entity merely for getting to the associations to be able to query them and binding the result to this object.
The alternative is that I have declared StoreBond { .. } class as the center of everything, which I find problematic over time.
Embeddable is problematic syntactically so I please do not entertain it for this purpose.
Not, sure what happens if you map such a StoreBond entity currently and then immediately after schema generation drop it from the database. I think that might still work on the JPA level, but not sure. It might be required to have certain ids populated which would be the basis for reaching out to the other associations?