I'm working on separating services. But there's something I'm not sure about. When separating services, it is difficult to separate entity values.
For example) Here is a part of my item entity.
@Entity
public class Item {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(nullable = false)
private Long itemId;
@ManyToOne
@JoinColumn(name = "category_id", nullable = false)
private Category category; // for query
@Column(nullable = false)
private boolean isOnSale; // for update
}
Let's say I want to separate this into a 'query' service and an 'update' service.
In this case, the 'query' service does not need to check the isOnSale column, and the 'update' service does not need to check the category column.
I want to use only the columns I need. So I did this.
- On 'query':
@Entity
public class Item {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(nullable = false)
private Long itemId;
@ManyToOne
@JoinColumn(name = "category_id", nullable = false)
private Category category; // for query
}
- On 'update':
@Entity
public class Item {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(nullable = false)
private Long itemId;
@Column(nullable = false)
private boolean isOnSale; // for update
}
From my small testing, it seems to work fine. (form Maria DB console...)(+A complete item table has already been created in the database.)
But I'm not sure if this is the right way. Is it okay to split the service like this?
(This is just a simple example of my problem! I have a slightly larger item entity and my service separation criteria is different...! Actually, what I'm trying to do is a little more similar to separating the 'purchase' of an item and the 'manipulation of details'.)