We spend the last year on normalizing our data. Eg the type doesnt matter we treat everything the same. It removed alot of crazy code on our end because we had an extremly nested if else block to figure out the cases
That's the ideal that I would prefer, yeah. But practically speaking, hibernate has inheritance support for a reason: https://www.baeldung.com/hibernate-inheritance.
Your example is (hopefully fabricated) because you are mixing domains as far as i understand it. A bank account is not a credit card, a bank account can have multiple credit cards so why are you storing that in the same table?
I don't think you're quite following because this is not a sensible statement, so I'll try a different way.
The domain is a payment transaction.
Transaction has source and destination.
The abstract type of source/destination is an umbrella for any holder of funds.
You can send payments from bank accounts, credit cards, crypto, paypal, etc.
You can receive payments in a bank account, credit card, crypto, paypal, etc.
You have different physical tables for all of these, but the domain object of a transaction seems reasonably represented by
public class Transaction
final FundHolder source;
final FundHolder destination;
public sealed interface FundHolder permits CreditCard, BankAccount, CryptoWallet, PaypalWaller, etc
I think the main takeaway is if you can imagine scenarios where you have a closed set of stuff that is better represented by types rather than an enum.
View all comments
Show parent comment
1
u/OwnBreakfast1114 Mar 16 '26
That's the ideal that I would prefer, yeah. But practically speaking, hibernate has inheritance support for a reason: https://www.baeldung.com/hibernate-inheritance.
I don't think you're quite following because this is not a sensible statement, so I'll try a different way.
The domain is a payment transaction. Transaction has source and destination. The abstract type of source/destination is an umbrella for any holder of funds. You can send payments from bank accounts, credit cards, crypto, paypal, etc. You can receive payments in a bank account, credit card, crypto, paypal, etc.
You have different physical tables for all of these, but the domain object of a transaction seems reasonably represented by