小编Gon*_*alo的帖子

Hibernate Criteria子查询

我需要使用detachedCriteria执行此SQL查询:

SELECT g.id FROM games g
WHERE NOT EXISTS (
    SELECT 1 FROM users_games ug WHERE ug.user_id = 1 AND g.id = ug.game_id)
Run Code Online (Sandbox Code Playgroud)

我们的想法是从不属于用户的游戏中获取ID.我尝试了10种不同的方法与detachedCriteria,但我得到"未知的实体:null"MappingException代码应如下所示:

DetachedCriteria subquery = DetachedCriteria.forClass(UserGame.class, "ug")
   .add(Restrictions.eq("ug.user.id", 1))
   .add(Restrictions.eqProperty("ug.game.id","u.id"));
DetachedCriteria criteria = DetachedCriteria.forClass(Game.class, "g")
   .add(Subqueries.notExists(subquery));
Run Code Online (Sandbox Code Playgroud)

设置预测只返回游戏的ID.

有任何想法吗?我认为Hibernate在没有别名的情况下加入查询时遇到了一些麻烦.添加别名有效,但结果非常错误.

java hibernate subquery

23
推荐指数
2
解决办法
5万
查看次数

如何使用jetty.port覆盖jetty.xml

我正在使用maven-jetty-plugin并尝试使用-Djetty.port = 8090覆盖我的jetty.xml设置,但它不起作用.只有当我从jetty.xml文件中删除连接器部分时,才会将端口设置为8090.

所以:

 mvn jetty:run -Djetty.port=8090
Run Code Online (Sandbox Code Playgroud)

连接器从端口8080开始

没有连接器在端口8090中启动

问题是我需要配置接受器,统计和其他东西.我尝试只从连接器中删除端口,但它不起作用.

我正在使用:

JAVA 1.7_05
MAVEN 3.0.4
Jetty 8.1.4
Linux Ubuntu 12.04 64bits
Run Code Online (Sandbox Code Playgroud)

这是我的pom.xml插件配置:

<plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>8.1.4.v20120524</version>
            <configuration>
                <stopKey>foo</stopKey>
                <stopPort>9990</stopPort>
                <jettyXml>src/main/webapp/WEB-INF/jetty.xml</jettyXml>
            </configuration>
            <executions>
                <execution>
                    <id>start-jetty</id>
                    <!-- <phase>pre-integration-test</phase> -->
                    <goals>
                        <goal>run</goal>
                    </goals>
                    <configuration>
                        <scanIntervalSeconds>0</scanIntervalSeconds>
                    </configuration>
                </execution>
                <execution>
                    <id>stop-jetty</id>
                    <!-- <phase>post-integration-test</phase> -->
                    <goals>
                        <goal>stop</goal>
                    </goals>
                </execution>
            </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

Jetty.xml连接器conf:

<Call name="addConnector">
  <Arg>
      <New class="org.eclipse.jetty.server.nio.SelectChannelConnector">
        <Set name="host"><Property name="jetty.host" /></Set>
        <Set name="port"><Property name="jetty.port" default="8080"/></Set>
        <Set name="maxIdleTime">300000</Set>
        <Set name="Acceptors">4</Set>
        <Set name="statsOn">false</Set>
        <Set name="confidentialPort">8443</Set>
    <Set name="lowResourcesConnections">20000</Set>
    <Set …
Run Code Online (Sandbox Code Playgroud)

java jetty embedded-jetty maven maven-jetty-plugin

11
推荐指数
2
解决办法
3万
查看次数

如果WebAppContext无法启动,如何取消启动或关闭jetty

我正在使用Maven Jetty插件,有没有办法防止服务器启动或关闭(例如使用maven-jetty-plugin)如果任何bean失败?

这是一个例子:

2013-04-22 11:43:59.327:WARN:oejw.WebAppContext:main: Failed startup of context o.e.j.m.p.JettyWebAppContext@9a681a{/,file:/opt/bamboo/bamboo-home/xml-data/build-dir/APA-BC-JETTYAPA/src/main/webapp/,STARTING}{file:/opt/bamboo/bamboo-home/xml-data/build-dir/APA-BC-JETTYAPA/src/main/webapp/}
org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/classes/applicationContext.xml]; nested exception is org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'staticDataService' for bean class [com.etermax.common.service.StaticDataService] conflicts with existing, non-compatible bean definition of same name and class [com.etermax.bingo.api.service.BingoStaticDataService]
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:412)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
        at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:124)
        at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:93)
        at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)
        at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:451)
        at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:272)
        at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:196)
        at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
        at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:778)
        at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:425)
        at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:770)
        at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:275) …
Run Code Online (Sandbox Code Playgroud)

java spring jetty maven-jetty-plugin

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

log4j截断堆栈跟踪

我在将堆栈跟踪打印到我的日志文件时遇到问题.Log4j.properties:

log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=/var/log/app/application.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %c{1} [%p] %m%n

log4j.rootLogger=warn, file
log4j.logger.com.app=info, file
log4j.additivity.com.app=false
Run Code Online (Sandbox Code Playgroud)

当我在我的类UserGuard.java中记录这样的异常时:

} catch (Exception e) {
    log.error("Uncaught error", e);
    response.setEntity(new StringRepresentation(" "));
    response.setStatus(Status.SERVER_ERROR_INTERNAL);
}
Run Code Online (Sandbox Code Playgroud)

这导致我的application.log:

2011-12-28 07:30:03 UserGuard [ERROR] Uncaught error
java.lang.NullPointerException
Run Code Online (Sandbox Code Playgroud)

没有显示堆栈跟踪.这真的很烦人.谢谢!

在另一台机器上尝试使用相同的pom.xml和相同的log4j.properties并且正常工作.我应该认为问题是我的java版本吗?

java log4j truncate exception stack-trace

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

Hibernate对数据库的查询

我遇到了hibernate对数据库进行查询的问题.在进行简单的选择时,这是我的查询日志(使用Mysql 5.1)到数据库:

111125  7:18:30
27 Query    SET autocommit=0
27 Query    SELECT @@session.tx_isolation
27 Query    select this_.id as id34_0_, this_.media_id as media3_34_0_, this_.message as message34_0_, this_.user_id as user4_34_0_ from notifications this_
27 Query    rollback
27 Query    SET autocommit=1
Run Code Online (Sandbox Code Playgroud)

我已经阅读了很多关于将自动提交设置为0然后再设置为1.我知道连接的默认值是1,并且无法更改此行为.您可以运行SET autocommit = 0但结果是相同的.

反正有没有避免任何这些疑问?我不知道为什么SELECT @@ session.tx_isolation正在发生和回滚.当我使用事务时,我得到一个提交然后回滚.不确定为什么回滚始终是有线的.

非常感谢!

我的conf:Spring 2.5.6,Hibernate 3.6.0,Mysql 5.1

datasoure.xml:

<bean id="dataSource" destroy-method="close"
    class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="${jdbc.driverClassName}" />
    <property name="url" value="${jdbc.url}" />
    <property name="username" value="${jdbc.username}" />
    <property name="password" value="${jdbc.password}" />

    <property name="initialSize" value="3" />
    <property name="maxActive" value="20" />
    <property name="minIdle" …
Run Code Online (Sandbox Code Playgroud)

mysql database spring hibernate

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