Код: Выделить всё
@Entity
// bid is a foreign key to B (id)
public class A
{
@Id
@GeneratedValue (strategy = GenerationType.IDENTITY)
@Getter
@Setter
private Long id;
@NotNull
@Column (unique = false)
@Getter
@Setter
private String name;
@Column (unique = false)
@Getter
@Setter
private Long bid; // foreign key to B (id)
@OneToOne
@JoinColumn (name = "bid", referencedColumnName = "id", insertable = false, updatable = false)
@Getter
private B b;
}
@Entity
public class B
{
@Id
@GeneratedValue (strategy = GenerationType.IDENTITY)
@Getter
@Setter
private Long id;
@NotNull
@Column (unique = false)
@Getter
@Setter
private String info;
}
Код: Выделить всё
public interface ARepo extends JpaRepository
{
public List findByName (String name);
}
Но мне не нужен весь B, мне нужен только B.info .
Могу ли я изменить @JoinColumn, чтобы получать только этот один элемент вместо всей строки?
Подробнее здесь: https://stackoverflow.com/questions/785 ... -whole-row