Which is the better approach? Let's say I have these two entities:
Approach A :
class Survey {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
int id;
@Column(name = "parent_id")
int parentId;
...
}
Approach B :
class Survey {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
int id;
@JoinColumn(name = "parent_id", referencedColumnName = "id")
@ManyToOne(optional = true)
Survey parent;
...
}
I am going to have lots of these types of relationships. Even with LAZY fetch strategy, B has following disadvantages :
- Caching of entities is not straightforward. Lazy loaded data (will/should it be cached or not?)
- If I ever need to serialize/deserialize these entities with jackson, this won't be straightforward.
I am inclined towards approach A, couldn't find any guidelines/comparisons of these two approaches. Any comparison or tips over which approach is preferable? Any major drawbacks/performance impact of approach A over B.
P.S. : This might be a stupid question but still I had to ask.
Aucun commentaire:
Enregistrer un commentaire