I am creating a simple blackjack game backed by databaseIn my Card ispublic class Card{ private Face face; private Suit suit; //setters.. getters}where face and suit are enumsI have an entity Bet with the following@Entitypublic class Bet{   private Player player;   private String cards;   //...}Currently when I'm dealing cards I parse the suit and face to string and concatenate them in the cards field and then parse the cards if I want to calculate the score. I find this cumbersome so I want to change my field cards to List in the Bet Entity.Now, if that's the case I would have to make the Card class an entity as well. But my cardService, which is where I get my cards, does not rely on the database, it just creates random cards so it does not make sense to make card an entity - am I right?
Entity design for a blackjack game - should I make Card an entity?
domain model;hibernate;entity
A card is a value, not an entity. Cards do not have identity -- if the pack contains two cards with the same value it is of no interest to identify them separately. They only have value.Programming languages tend to provide values like integer, string and struct. You need to pick one of those to represent the value of a card. I would suggest using integer for the value, and write a class that can convert that integer to and from string or image representation, and to return the rank, suit and order (which may not be the same as the integer order).Then your generator simply generates integers within a specified range.The usual deck of cards contains 53 distinct cards, including a Joker. There are games (500) that have up to 63 distinct cards but the principle is the same, and an integer is a perfectly convenient way to encode the value. I would use that in the database too.For a hand or a deal you have multiple cards, up to 13 in Bridge or 52 if you want to keep a complete deal. You could encode that as a space-separated list of integers or some other way, depending on what you need. That's getting off the original point.For clarity, I do not suggest for a moment that one should use actual integers in the code to represent cards. In Java or JavaScript I would use a class, in C# or C++ a struct. The problem is that an object has identity but we want to deal with values. We want two different card objects that have the same value to compare equal. The simplest way (but not the only way) to do that is for the card object to contain an integer so that two cards with the same integer value are the same value. This is done by implementing a 'Compare Equal' operator in the class that compares the integer value.This is a subtle issue, the representation of value types, and not easily addressed with an audience of widely different skills.