什么样的结果可以返回@Formula注释? (休眠)

时间:2015-06-05 13:45:46

标签: java hibernate jpa

在关于Hibernate的public string GetAllGroups() { int count = 1; string getDListScript = @"C:\inetpub\wwwroot\O365Service\Scripts\GetDList.ps1"; string userName = "j*****"; string password = "****"; try { using (var ps = PowerShell.Create()) { Runspace runSpace = RunspaceFactory.CreateRunspace(); runSpace.Open(); ps.Runspace = runSpace; ps.AddCommand(getDListScript).AddParameter("Office365Username", userName).AddParameter("Office365Password", password); //IAsyncResult async = ps.BeginInvoke(); //StringBuilder stringBuilder = new StringBuilder(); var results = ps.Invoke(); PSDataCollection<ErrorRecord> errors = ps.Streams.Error; if (errors != null && errors.Count > 0) { StringBuilder sb = new StringBuilder(); foreach (ErrorRecord err in errors) { sb.Append(err.ToString()); } System.IO.File.WriteAllText(@"C:\inetpub\wwwroot\RestService\bin\err.text", sb.ToString()); } count = results.Count; } } catch (Exception ex) { return ex.Message.ToString(); } return count.ToString(); } 注释的每个指南或示例中,结果都是一个简单的对象,例如,字符串或计算的长数。我想使用这样的注释:

@Formula

这可能吗?我应该避免@Entity @Table(name = "my_first_table") public class MyFirstEntity { @Column(name = "pattern") private String pattern; @Formula(value = "select b from MySecondEntity b where b.name like pattern") private Set<MySecondEntity> mySecondEntities; } 注释,因为@OneToMany上的更改可能会出现问题。

1 个答案:

答案 0 :(得分:0)

休眠@Formula不能包含这样的完整SQL查询。

它包含任何SQL子句,该子句可以是查询中的单个列。

例如:

@Formula("income * tax / 100")