I have 2 entities that persist into a DB.
@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;
}
This is working well.
public interface ARepo extends JpaRepository <A, Long>
{
public List <A> findByName (String name);
}
findByName delivers A-objects where member getB returns object of B.
But I do not want the whole B, I only want B.info.
Can I change the @JoinColumn to get only that single element instead of the whole row?