小编Ham*_*riZ的帖子

Hibernate - 在where子句中使用外键时避免不必要的连接

我尝试在Hibernate中优化数据库查询,但我找到了一个阻止程序:

<class name="SupportedLanguageVO" table="AR_SUPPORTED_LANG" >
    <cache usage="read-only"/>
 <id name="Id" type="java.math.BigInteger">
  <column name="ID" sql-type="NUMBER(20)" not-null="true"/>
  <generator class="assigned"/>
 </id>
    <property name="OrderSeq" type="java.math.BigInteger">
  <column name="ORDER_SEQ" sql-type="NUMBER(20)" not-null="true"/>
 </property>
    <many-to-one name="Country" class="CountryVO" column="CTRY_CD_ID" cascade="none" >
    <many-to-one name="Language" class="LanguageVO" column="LANG_CD" cascade="none" >

    </class>
Run Code Online (Sandbox Code Playgroud)

国家的主要关键是CTRY_CD_ID.如果我运行以下标准

  Criteria crit = m_Session.createCriteria(SupportedLanguageVO.class);
            crit.createCriteria("Country").add(Restrictions.eq("_CountryCode", p_countrycode));
            crit.addOrder(Order.asc("OrderSeq"));
Run Code Online (Sandbox Code Playgroud)

我可以看到,hibernate加入了ctry和AR_SUPPORTED_LANG表.为什么?跑步会更好

select * from AR_SUPPORTED_LANG where ctry_cd_id=?
Run Code Online (Sandbox Code Playgroud)

sql而不是

select * from AR_SUPPORTED_LANG inner join ctry .... where ctry_cd_id=?
Run Code Online (Sandbox Code Playgroud)

我可以强制hibernate运行第一个查询吗?

sql hibernate fetch hibernate-mapping

5
推荐指数
1
解决办法
3077
查看次数

Hibernate的Nullpointer开始交易

我正在使用带有连接池数据源的hibernate

<bean id="dataSource" class="oracle.jdbc.pool.OracleDataSource"  destroy-method="close">
            <property name="connectionCachingEnabled" value="true" />
        <property name="URL">
            <value>${jdbc.url}</value>
        </property>
        <property name="user">
            <value>${jdbc.username}</value>
        </property>
        <property name="password">
            <value>${jdbc.password}</value>
        </property>
        <property name="connectionCacheProperties">
          <value>
            MinLimit:10
            MaxLimit:75
            InitialLimit:10
            ConnectionWaitTimeout:120
            InactivityTimeout:180
            ValidateConnection:true
            MaxStatementsLimit:0
          </value>
       </property>
    </bean>



<bean id="hibernatePropertyConfigurer"
      class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="hibernate.properties"/>
</bean>

<!-- Database Property -->
<bean id="hibernatePropertiesPearl"
      class="org.springframework.beans.factory.config.PropertiesFactoryBean">
    <property name="properties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
            <prop key="hibernate.cache.provider_class">MyCacheProvider</prop>
            <prop key="hibernate.show_sql">false</prop>
            <prop key="hibernate.max_fetch_depth">0</prop>
            <prop key="hibernate.jdbc.batch_size">0</prop>
            <prop key="hibernate.cache.use_query_cache">true</prop>
            <prop key="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory
            </prop>
            <prop key="hibernate.connection.autocommit">false</prop>
            <prop key="hibernate.transaction.manager_lookup_class">
                org.hibernate.transaction.JBossTransactionManagerLookup
            </prop>
            <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</prop>
            <prop key="hibernate.transaction.auto_close_session">false</prop>
        </props>
    </property>
</bean>
Run Code Online (Sandbox Code Playgroud)

我可以看到,连接在数据库中成功打开并且工作正常,但过了一段时间我在日志中收到以下错误消息并且服务器刚刚死掉: …

java hibernate connection-pooling nullpointerexception

5
推荐指数
1
解决办法
2101
查看次数

使用比较运算符匹配元组

我想匹配元组模式,但我找不到任何解决方案如何匹配使用比较运算符.我的代码是:

myTuple  match {       
      case (-1,-1,true) => ...       
      case (_>=0,-1,_) =>  ...
    }
Run Code Online (Sandbox Code Playgroud)

这给出了编译时错误.我也尝试使用if guard,但是我认为它不能以这种方式应用:

 case (_ if _>=0,-1,_) =>  ...
Run Code Online (Sandbox Code Playgroud)

我的方法是正确的还是我应该以不同的方式解决这个问题?谢谢Zoltan

scala pattern-matching

5
推荐指数
1
解决办法
225
查看次数

JavaFX和Vaadin之间的区别

我认为JavaFX和Vaadin非常相似,只是JavaFX在浏览器中需要Java插件.但否则它似乎提供相同的功能.为什么我更喜欢Vaadin和JavaFX?Vaadin是否是更好的解决方案?

javafx vaadin

5
推荐指数
1
解决办法
2978
查看次数

Scala特征语法

我正在阅读Odersky的书,下面是一个带有以下代码部分的speadsheet示例:

package org.stairwaybook.scells
    trait Arithmetic { this: Evaluator =>
      operations += (
        "add"  -> { case List(x, y) => x + y },
        "sub"  -> { case List(x, y) => x - y },
        "div"  -> { case List(x, y) => x / y },
        "mul"  -> { case List(x, y) => x * y },
        "mod"  -> { case List(x, y) => x % y },
        "sum"  -> { xs => (0.0 /: xs)(_ + _) },
        "prod" -> …
Run Code Online (Sandbox Code Playgroud)

scala

3
推荐指数
1
解决办法
537
查看次数

返回类型的递归函数

什么是一般类型fs

 lazy val fs  = List(2,3,4).zip(fs.tail)
Run Code Online (Sandbox Code Playgroud)

编译器要求在编译时设置它.

更新:我想考虑第二个项目欧拉问题的解决方案:

    lazy val fs: Stream[Int] =
      0 #:: 1 #:: fs.zip(fs.tail).map(p => p._1 + p._2)

   fs.view.takeWhile(_ <= 4000000).filter(_ % 2 == 0).sum
Run Code Online (Sandbox Code Playgroud)

我只是想调试在这些步骤中发生的事情

scala

3
推荐指数
1
解决办法
573
查看次数

MS SQL唯一密钥 - 错误或功能?

我在MS SQL中有一个表,我有一个TERMINAL varchar(50)列,我有一个唯一的密钥.当我尝试插入记录'HOST1'然后'HOST1'时,我收到了英国密钥违规异常.为什么MS sql处理这两个字符串,因为它们是相同的?

谢谢Z.

sql sql-server sql-server-2008

3
推荐指数
1
解决办法
172
查看次数

关闭ResultSet但不关闭PreparedStatement

如果 ResultSet 关闭,但PreparedStatement 不关闭,我会预期什么类型的资源泄漏。非常怀疑它可能会导致打开游标问题......

   PreparedStatement p = connection.prepareStatement(...);
    try {
      ResultSet r = p.executeQuery();
      try {
        while (r.next()) {
          ....
        }
      } finally {
        try {
          r.close();
        } catch (SQLException e) {
        // log this or something -- prevent these from masking original exception
        }
      }
    }
Run Code Online (Sandbox Code Playgroud)

是Oracle 11g,jdbc 11.2.0.3

谢谢

请尝试回答我的问题,而不是专注于修复

java oracle jdbc

3
推荐指数
1
解决办法
2137
查看次数

普罗米修斯时间序列在没有更新的情况下持续多长时间

如果我向 Prometheus 发送一个仪表,则有效负载具有时间戳和如下值:

指标名称{标签=“值”} 2.0 16239938546837

如果我在普罗米修斯上查询它,我可以看到一条连续的线。如果不发送相同指标的有效负载,线路就会停止。几分钟后发送相同的指标,我得到另一条连续的线路,但它没有与旧线路连接。

普罗米修斯是否修复了时间序列在没有更新的情况下持续多长时间的问题?

time-series prometheus

3
推荐指数
1
解决办法
2955
查看次数

Scala代码 - 错误:缺少参数类型错误

这段代码有什么问题?

object Numbers extends App {

  def decode(number: Int) : String = number match {
    case _ if _ % 15==0 => "fizzbuzz"
    case _ if _ % 3==0 => "fizz"
    case _ if _ % 5==0 => "buzz"
    case _ => _.toString
  }

  val test = List(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15)
  test.map(decode).foreach(println)
}
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

error: missing parameter type for expanded function
The argument types of an anonymous function must be fully known. (SLS 8.5)
Expected type was: String
case _ if _%15==0 => …
Run Code Online (Sandbox Code Playgroud)

scala

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

如何编写一个通用迭代器来保持状态并返回值而不使用克隆?

我尝试编写一个通用迭代器,但我不知道如何在不使用clone. 有什么方法可以在函数中创建变量next并返回引用吗?如果我替换Tu32,那么我可以只返回Some(self.count),但是使用泛型,这是不可能的。

use num_traits::Num;
use std::clone::Clone;

struct Counter<T>
where
    T: Num + Clone,
{
    count: T,
}

impl<T> Counter<T>
where
    T: Num + Clone,
{
    fn new() -> Counter<T> {
        Counter { count: T::zero() }
    }
}

impl<T> Iterator for Counter<T>
where
    T: Num + Clone,
{
    type Item = T;

    fn next(&mut self) -> Option<Self::Item> {
        self.count = self.count.clone() + T::one();
        Some(self.count.clone())
    }
}

fn main() {
    let mut …
Run Code Online (Sandbox Code Playgroud)

generics iterator clone rust

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