Skip to main content
2 of 3
added 437 characters in body
Christophe
  • 82.2k
  • 11
  • 136
  • 202

There is a discrepancy between the designed diagram and the generated keys:

  • you designed a one-to-many relationship for Wallet with WalletPlatform, WalletStorage and CryptoCurrency (i.e. one wallet could have several platforms, storage or currencies), but
  • the foreign keys generated by Hibernate in the Wallet implement a many-to-one in the opposite direction (i.e. a wallet can have only one platform, storage or currency, but those could be associated with several wallets).

Is it possible that you have a mismatch in the Hibernate definition of the associations/relations? In case of doubt, don't hesitate to update your question with the annotations you've used.

Looking further, it appears that there is an error with the relationship between Wallet and CryptoCurrency, in both the designed diagram and the foreign keys:

  • according to your diagram, a Wallet can be associated with several CryptoCurrency rows, but each crypto-currency can only be associated to a single wallet. For example, only one wallet could use bitcoins?? Are there really many more currenclies than there are wallets in your system?
  • according to the generated FK, a wallet could be associated to a single currency, but a currency could be used by several wallets.

This seems not correct: I understand that a wallet should be able to hold several crypto-currencies, and a crypto-currency can be held by several wallets. That's many-to-many. This is a reality of the domain model and it makes no sense to avoid many-to-many for obscure reasons. The many-to-many association implies the use of an association table, and hibernate is perfectly able to generate it.

Of course, if you really want to avoid many-to-many, you could use an intermediate entity (e.g.CurrencyInWallet), and two one-to-many associations to replace the many-to-many. But what would be the advantage?

Christophe
  • 82.2k
  • 11
  • 136
  • 202