The relationship '@ManyToOne' there any way that I can bring only the identifier of the relationship table without having to load the related entity?
Code:
@Entity
@Table(name = "City")
public class City {
private static final long serialVersionUID = 6600321365958270110L;
public static final int TAMANHO_MAXIMO_NOME_City = 255;
@Id
@SequenceGenerator(name = "City_SEQ", sequenceName = "City_SEQ")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "City_SEQ")
@Column(name = "CDCity", nullable = false)
private Long codigo;
@Column(name = "NMCity", nullable = false, unique = true, length = City.TAMANHO_MAXIMO_NOME_City)
private String nome;
@ManyToOne(fetch = FetchType.LAZY)//
@JoinColumn(name = "CDState", nullable = false)
private State state;
//...
}
When you press the 'CITY' no load 'State' but carrying its identifier.
example:
Code:
QUERY = 'SELECT city FROM City city'
City {
codigo 1,
nome 'test',
State {
codigo 100,
nome null,
nome2 null,
nome3 null,
}
}