I am using Spring boot. To save my entities on relational database, I configured a datasource and my domain classes, e.g.:
@Entity
@Table(schema = "schema_name", name = "tb_name")
public class table_name extends DomainEntity<Long> {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "ID_TABLE_NAME", nullable = false, updatable = false, precision = 12)
@SequenceGenerator(name = "sqTableName", sequenceName = "SQ_TABLE_NAME", initialValue = 1, allocationSize = 1)
@GeneratedValue(generator = "sqTableName", strategy = GenerationType.SEQUENCE)
private Long id;
@NotNull
@ManyToOne
@JoinColumn(name = "ID_OTHER_COLUMN", referencedColumnName = "ID_OTHER_COLUMN", nullable = false)
private OtherObject obj;
Using this tutorial: https://www.baeldung.com/spring-data-redis-tutorial, I configured my domain class Student:
@RedisHash("Student")
public class Student implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
public enum Gender {
MALE, FEMALE
}
private String id;
private String name;
private Gender gender;
private int grade;
}
When a class is anotated with @RedisHash
, when I use .save method, it saves this entity on Redis.
I would like to use this domain class in a relational database WITHOUT duplicating the file to save, sometimes on Redis and sometimes in a relational database. I searched, but I didn't find anything.
Can someone help?
You could define the domain class without the annotation @RedisHash
and make an empty subclass of the domain class for each database.
The domain class for redis would have the @RedisHash
annotation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With