Based on the question asked here: Hibernate - Foreign keys instead of Entities
If I were to implement the following example:
@JoinColumn(name="message_key")
@ManyToOne(targetEntity=Message.class,fetch=FetchType.LAZY)
private Message message;
@Column(name="message_key", updatable=false, insertable=false)
private Long message_fk;
Wouldn't this affect Entity
to DTO
conversion? In this case, during conversion, the object graph will include the mappings of the Message
object as well?
Would the following code behave in the exact same manner without the traversal of the Message
object?
@Entity
@Table(name = "table")
public class Example {
@Id
@GeneratedValue
private Long id;
// more properties
@Column(name = "message_key")
private Long messageKey;
// more properties
@Override
public Long getMessageKey() {
return messageKey();
}
@Override
public void setMessageKey(Long messageKey) {
this.messageKey = messageKey;
}
// More getters and setters
}
In this case, there is already a column in the DDL for table
named message_key
, so a foreign key relationship is not entirely necessary however I just need the generated id
to populate that column.