hibernate @JoinColumnsOrFormulas

@Entity
public class LineData{
	@Id
	public String getId(){ 
		return this.id; 
	}

	@Column
	public String getText() { 
		return this.text; 
	}
}

@Entity
public class Something{
	@Id
	public String getId() {	
		return this.id;	
	}
	@ManyToOne(fetch=FetchType.LAZY,optional=true)
	@JoinColumnsOrFormulas({ 
		@JoinColumnOrFormula(formula=@JoinFormula(value="(SELECT l.id from line_data l where text='something'", referencedColumnName="ID")) 
	})
	public LineData getLineData(){ 
		return lineData; 
	}
}

 

 

select something0_.ID as LINEID504_0_, linedata2_.ID as LINEID493_1_, 
(SELECT l.id from line_data l where text='something') as formula23_0_ 
from something something0_ 
left outer join line_data linedata2_ on
(SELECT l.id from line_data l where text='something')=linedata2_.ID

 

你可能感兴趣的:(hibernate @JoinColumnsOrFormulas)