小编Era*_*tes的帖子

JPA 使用 NO LOCK 读取数据

在我们正在编写的应用程序中,我们需要with(NOLOCK)在查询中使用 。只是为了使查询不会花费很长时间来处理。

我还没有找到任何关于如何实现这一点的信息。我确实发现了如何启用乐观或悲观锁定,但据我所知,这是用于写入数据,而不是读取数据。

有没有办法做到这一点?

我们使用 JPA 和 Criteria API 连接到 MSSQL 服务器,应用程序服务器是 Glassfish 4。

埃特斯

sql sql-server jpa criteria-api jakarta-ee

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

SAXParser 不允许 Xinclude

我正在尝试解组包含<xi:include>标签的 xml 文档。但是 SAXParser 不允许这样做,即使我特别告诉 SAXParserFactory 允许它。

Java代码:

SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setXIncludeaware(true);
spf.setNamespaceAwere(true);

spf.setFeature("http://apache.org/xml/features/xinclude", true);
spf.setFeature("http://apache.org/xml/features/xinclude/fixup-base-uris", true);

XMLReader xr = spf.newSAXParser().getXMLReader();
SAXSource source = new SAXSource(xr, new InputSource(inputStream));
JAXBElement<MyClass> el = unmarshaller.unmarshal(source, MyClass.class);
Run Code Online (Sandbox Code Playgroud)

要读取的 XML 文档

<?xml version="1.0" encoding="UTF-8"?>
<extension xmlns="http://www.example.com/test" xmlns:ext="http://www.example.com/test" xmlns:xi="http://www.w3.org/2003/XInclude">
    <visibility>
        <resourceConstraints>
            <resourceConstraint ext:resourceId="resourceOne">
                <role ext:show="true">AdminUsers</role>
            </resourceConstraint>
            <resourceConstraint ext:resourceId="resourceTwo">
                <role ext:show="true">AdminUsers</role>
            </resourceConstraint>
        </resourceConstraints>
        <xi:include href="extraContent.xml" />
    </visibility>
</extension>
Run Code Online (Sandbox Code Playgroud)

当我运行它时,我得到这个异常:

org.xml.sax.SAXParseException; lineNumber: 12; columnNumber: 50; cvc-complex-type.2.4.a: Invalid content was found starting with element 'xi:include'. One …
Run Code Online (Sandbox Code Playgroud)

java xml sax xinclude

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

JPA CriteriaBuilder 值如列

我正在尝试使用 CriteriaBuilder 创建一个查询,其中我需要一个谓词,其中谓词的值类似于数据库中的值。

基本上,我需要能够做到以下几点: WHERE myTestValue LIKE columnValue

在本机查询中,这是一个选项,但使用 CriteriaBuilder 或 NamedQueries,它似乎不起作用。

String myValue = "foo@bar.com";
cb.where(cb.like(myValue, root.get(Entity_.email));
Run Code Online (Sandbox Code Playgroud)

JPA 中是否有选项可以这样做?还是我应该回退到本机查询?

编辑 我需要能够检查给定值是否与数据库中的通配符条目匹配。所以数据库有一个记录%@bar.com%,我需要检查我的给定值是否foo@bar.com与该记录匹配。

java jpa eclipselink criteria-api

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

使用CDI注入PersistenceContext

目前,我正在使用PersistenceContext来注入EntityManager.EM完美注入.

@Stateless
public StatelessSessionBean implements StatelessSessionBeanLocal {

    @PersistenceContext(unitName = "MyPersistenceUnit")
    private EntityManager em;

    @Override
    public Collection<MyObject> getAllObjects(){
        CriteriaBuilder cb = em.getCriteriaBuilder();
        CriteriqQuery<MyObject> query = cb.createQuery(MyObject.class);
        query.from(MyObject);
        return em.createQuery(query).getResultList();
    }
}
Run Code Online (Sandbox Code Playgroud)

现在我尝试装饰豆子,突然间em没有被注射.我得到一个NullPointerException.

@Decorator
public StatelessSessionBeanDecorator implements StatelessSessionBeanLocal {

    @Inject
    @Delegate
    @Any
    StatelessSessionBeanLocal sb

    @Override
    public Collection<MyObject> getAllObjects(){
        System.out.println("Decorated method!");
        return sb.getAllObjects();
    }
}
Run Code Online (Sandbox Code Playgroud)

我知道EJB和CDI是两个完全不同的管理器,所以那个人不了解另一个.我期望@PersistenceContext是一个EJB注入点,而@Inject是一个CDI注入点.我该怎么做才能解决这个问题并让EntityManager按照它应该注入?

java ejb glassfish java-ee cdi

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

Maven 尝试两次部署同一个工件

我正在使用 Maven 来构建我的项目,但是当我运行命令时mvn clean package deploy,它会尝试部署工件两次。我将 build-helper-maven-plugin 插件配置为附加我使用自定义插件创建的 ear 文件。

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>1.9.1</version>
            <executions>
                <execution>
                    <id>attach-artifacts</id>
                    <phase>package</phase>
                    <goals>
                        <goal>attach-artifact</goal>
                    </goals>
                    <configuration>
                        <artifacts>
                            <artifact>
                                <file>${project.build.directory}/${project.artifactId}-${project.version}.ear</file>
                                <type>ear</type>
                            </artifact>
                        </artifacts>
                    </configuration>
                </execution>
            </executions>
        </plugin>
Run Code Online (Sandbox Code Playgroud)

当我禁用 build-helper-maven-plugin 时,剩余的工件(仅 pom)仅上传一次。

我应该怎么做才能让 Maven 只部署一次额外的 ear 文件?

埃特斯

编辑

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>my.group.id</groupId>
    <artifactId>my.artifact.id</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>pom</packaging>

    <name>My Project</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <scm>
        <!-- Config -->
    </scm>

    <distributionManagement>
        <repository>
            <!-- Config -->
        </repository>
        <snapshotRepository>
            <!-- Config -->
        </snapshotRepository>
    </distributionManagement> …
Run Code Online (Sandbox Code Playgroud)

java maven

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

JavaFX 2窗口图标不起作用

我正在尝试向我的JavaFX 2应用程序添加一个Icon,但我找到的方法似乎不起作用.

Image icon = new Image(getClass().getResourceAsStream("/images/icon.png"));
stage.getIcons().add(icon);
Run Code Online (Sandbox Code Playgroud)

图标大小为32x32.

当我尝试

Image icon = new Image("http://goo.gl/kYEQl");
Run Code Online (Sandbox Code Playgroud)

它在Netbeans和可运行的jar中都有效.

我希望这可以解决.

java icons jar executable-jar javafx-2

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