小编Nic*_*400的帖子

如何在休眠时使用HAVING COUNT(*)

我需要创建一个查询,我需要COUNT(*)HAVING COUNT(*) = x.

我正在使用一个使用CustomProjection该类的工作,我在某处下载了.

这是我尝试实现的SQL:

select count(*) as y0_, this_.ensayo_id as y1_ from Repeticiones this_
inner join Lineas linea1_ on this_.linea_id=linea1_.id
where this_.pesoKGHA>0.0 and this_.nroRepeticion=1 and linea1_.id in (18,24)
group by this_.ensayo_id
having count(*) = 2
Run Code Online (Sandbox Code Playgroud)

这是我使用ProjectionHibernate类的代码:

critRepeticion.setProjection(Projections.projectionList()
                .add( Projections.groupProperty("ensayo") )
                .add( CustomProjections.groupByHaving("ensayo_id",Hibernate.LONG,"COUNT(ensayo_id) = "+String.valueOf(lineas.size()))
                .add( Projections.rowCount() )
                );
Run Code Online (Sandbox Code Playgroud)

错误是:

!STACK 0
java.lang.NullPointerException
at org.hibernate.criterion.ProjectionList.toSqlString(ProjectionList.java:50)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getSelect(CriteriaQueryTranslator.java:310)
at org.hibernate.loader.criteria.CriteriaJoinWalker.<init>(CriteriaJoinWalker.java:71)
at org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:67)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1550)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
at ar.com.cse.cseagro.controller.RepeticionController.buscarEnsayo(RepeticionController.java:101)
Run Code Online (Sandbox Code Playgroud)

如果我用CustomProjections类注释该行,查询工作,但我没有得到HAVING …

hibernate having-clause

10
推荐指数
1
解决办法
1万
查看次数

如何在视图模型中从 DataStore 首选项(如 Flow)获取值

我遇到了一个情况,我可以通过 SharedPreferences 解决。但现在我正在迁移到 kotlin 和 DataStore。

我遇到了这个问题。

我有一个字符串值存储在共享首选项以及其他键值对中。此字符串是一个 URL,用于 Retrofit 调用的 baseUrl 参数中。

我的问题是,当我在 ViewModel 中运行时,检索 Fragment 值的正确方法是什么。

这是我的代码的一部分:

@Singleton
class PreferencesManager @Inject constructor(
    @ApplicationContext context: Context,
    anioDao: AnioDao
) {

   val baseUrlFlow = dataStore.data
        .catch { exception ->
            if (exception is IOException) {
                Log.e(TAG, "Error reading preferences: ", exception)
                emit(emptyPreferences())
            } else {
                throw exception
            }
        }
        .map {
            it[PreferencesKeys.BASER_URL] ?: "http://192.168.2.109:1337"
        }

}
Run Code Online (Sandbox Code Playgroud)

然后在 ViewModel 类中

class EnsayosViewModel @ViewModelInject constructor(
    private val ensayoRepository: EnsayoRepository,
    private val anioRepository: AnioRepository, …
Run Code Online (Sandbox Code Playgroud)

android kotlin android-jetpack-datastore

9
推荐指数
1
解决办法
1万
查看次数

什么是"|"的功能 (管道)操作员?

我从另一个地方复制了这一行:

Total += parseFloat($(this).val())|0;
Run Code Online (Sandbox Code Playgroud)

操作员的功能是|什么?当我改变数字时,我会得到不同的结果.

javascript operators

2
推荐指数
1
解决办法
1523
查看次数