小编Gre*_*reg的帖子

JPA Criteria Query不同

我正在尝试编写一个不同的条件查询,使用:

CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<RuleVar> query = builder.createQuery(RuleVar.class);
Root<RuleVar> ruleVariableRoot = query.from(RuleVar.class);
query.select(ruleVariableRoot.get("foo").<String>get("foo")).distinct(true);
Run Code Online (Sandbox Code Playgroud)

基于CriteriaQuery.select()的javadoc中的示例

CriteriaQuery<String> q = cb.createQuery(String.class);
 Root<Order> order = q.from(Order.class);
 q.select(order.get("shippingAddress").<String>get("state"));
Run Code Online (Sandbox Code Playgroud)

但是,这给了我一个错误:

The method select(Selection<? extends RuleVar>) in the type CriteriaQuery<RuleVar> is not applicable for the arguments (Path<String>)
Run Code Online (Sandbox Code Playgroud)

有人可以指出我做错了什么吗?或者如何从Path获取Selection对象?

java jpa criteria-api

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

JPA条件查询加载整个表

我觉得这是一个愚蠢的问题,但我找不到答案.我有一个课程如下:

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

@Entity
@Table(name="DEMO_VARIABLES")
public class Variable implements Serializable
{
    private static final long serialVersionUID = -1734898766626582592L;

    @Id
    @SequenceGenerator(name="VARIABLE_ID_GENERATOR", sequenceName="DEMO_VARIABLE_ID_SEQ", allocationSize=1)
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="VARIABLE_ID_GENERATOR")
    @Column(name="VARIABLE_ID", unique=true, nullable=false, precision=22)
    private long variableId;

    @Column(name="VARIABLE_NAME", nullable=false, length=50)
    private String variableName;

    @Column(name="VARIABLE_VALUE", nullable=false, length=500)
    private String variableValue;

    public Variable()
    {

    }

    public long getVariableId()
    {
        return variableId;
    }

    public void setVariableId(long variableId)
    {
        this.variableId = variableId;
    }

    public String getVariableName() …
Run Code Online (Sandbox Code Playgroud)

jpa criteria-api

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

如何锁定maven插件版本

如何锁定我想要使用的Maven插件的版本?

我有PMD插件配置如下:

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-pmd-plugin</artifactId>
                <version>2.5</version>
                <configuration>
                    <outputDirectory>target/pmd</outputDirectory>
                    <targetDirectory>target/</targetDirectory>
                    <aggregate>true</aggregate>
                    <targetJdk>1.6</targetJdk>
                    <rulesets>
                        <ruleset>rulesets/basic.xml</ruleset>
                        <ruleset>rulesets/codesize.xml</ruleset>
                        <ruleset>rulesets/coupling.xml</ruleset>
                        <ruleset>rulesets/design.xml</ruleset>
                        <ruleset>rulesets/imports.xml</ruleset>
                        <ruleset>rulesets/logging-java.xml</ruleset>
                        <ruleset>rulesets/optimizations.xml</ruleset>
                        <ruleset>rulesets/strings.xml</ruleset>
                        <ruleset>rulesets/unusedcode.xml</ruleset>
                    </rulesets>
                </configuration>
            </plugin>
Run Code Online (Sandbox Code Playgroud)

昨晚,我的夜间构建失败,我不能再运行任何pmd目标,因为它试图找到该插件的2.6-SNAPSHOT版本.如果我有一个2.5的版本标签,它为什么甚至试图找到2.6-SNAPSHOT?此外,2.6-SNAPSHOT不在中心 - 为什么我的maven客户认为它存在?

Maven版本:2.0.9
Java版本:1.6.0_17
操作系统名称:"linux"版本:"2.6.24-24-generic"arch:"i386"系列:"unix"

编辑:

我升级到maven 2.2.1并观察到与以前相同的问题.通过从我的存储库(.m2/repository/org/apache/maven/plugins/maven-pmd-plugin/maven-metadata-central.xml)中的元数据中删除2.6-SNAPSHOT,我能够构建项目.我还将latestVersion标记设置为2.5.这显然不是解决方案,因为我必须部署自己的插件或更改所有客户端上的缓存版本.

maven-2 pmd

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

无法让c3p0与Spring/Hibernate/JPA一起使用

我已经将我的Spring应用程序配置为使用Hibernate作为JPA提供程序.应用程序上下文如下所示:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:util="http://www.springframework.org/schema/util"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

    <context:component-scan base-package="com.med.persistence.magic.*"/>
    <aop:aspectj-autoproxy />

    <!-- Load DB config file -->
    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="ignoreResourceNotFound" value="true" />
        <property name="ignoreUnresolvablePlaceholders" value="true" />
        <property name="searchSystemEnvironment" value="true" />
        <property name="systemPropertiesMode">
            <util:constant
                static-field="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_OVERRIDE" />
        </property>
        <property name="locations">
            <list>
                <value>classpath:dev.db.properties</value>
<!--                <value>file:///usr/share/tomcat6/conf/hx_db.conf</value>-->
            </list>
        </property>
    </bean>

    <tx:annotation-driven transaction-manager="transactionManager"/>

    <bean id="transactionManager" class = "org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory"/>
    </bean>

     <bean id="jpaAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
        <property name="showSql" value="true" />
    </bean>

    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> …
Run Code Online (Sandbox Code Playgroud)

spring hibernate jpa c3p0

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

标签 统计

jpa ×3

criteria-api ×2

c3p0 ×1

hibernate ×1

java ×1

maven-2 ×1

pmd ×1

spring ×1