小编Gan*_*alf的帖子

Hibernate在关系中创建错误的实体子类型

我有一个奇怪的问题,hibernate不会在多对一关系中创建预期的实体类型.我们有以下具有子类层次结构的实体(简化):

@Entity
@Table(name = "A")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "DISCRIMINATOR", discriminatorType = DiscriminatorType.STRING, length = 1)
public abstract class A {

    @Id
    ...
    public Long getId() { ... }
    ...
}

@Entity
@DiscriminatorValue("1")
public class A1 extends A {
    ...
}

@Entity
@DiscriminatorValue("2")
public class A2 extends A {
    ...
}


@Entity
@Table(name = "B")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "DISCRIMINATOR", discriminatorType = DiscriminatorType.STRING, length = 1)
public abstract class B<AClass extends A> {

    protected AClass a;

    @Id
    ... …
Run Code Online (Sandbox Code Playgroud)

java hibernate jpa discriminator

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

如何在Eclipse和Ant中使用不同的Junit TestRunner?

我有几个JBehave测试,我想从Eclipse和Ant运行.在Eclipse中,我希望看到一个包含在图形输出中执行的所有不同故事,场景和步骤的树,因此我在执行此操作的测试中添加了一个自定义运行器:

@RunWith(de.codecentric.jbehave.junit.monitoring.JUnitReportingRunner.class)
public class MyStoryTest extends org.jbehave.core.junit.JUnitStories
{
    // ...
}
Run Code Online (Sandbox Code Playgroud)

但是相反,当使用Ant和Continuous Integration服务器运行测试时,我希望只将每个故事都看作输出中的单个项目.这通常在没有任何注释的情况下实现:

public class MyStoryTest extends JUnitStories
{
    // ...
}
Run Code Online (Sandbox Code Playgroud)

那么我如何告诉Ant(junit Ant任务)使用与Eclipse不同的跑步者?让事情变得更复杂:目前我在Eclipse(而不是Ant)中使用测试套件来运行测试:

@RunWith(org.junit.extensions.cpsuite.ClasspathSuite.class)
@org.junit.extensions.cpsuite.ClassnameFilters("foo.mypackage.tests.*")
public class MyStoriesTestSuite
{
    // Nothing more to say ;)
}
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

干杯,蒂尔曼

java ant junit test-runner jbehave

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

QueryDSL JPA语法错误包含在Set?

我有一个类似于以下的JPA实体bean:

@Entity
class License {
    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(name = "LicenseTags")
    Set<Tag> tags;

    // Skipped remaining members
}
Run Code Online (Sandbox Code Playgroud)

Tag本身也是一个Entityid和一个名字.现在我想查询附加了某些标签的许可证.当我尝试以下查询

Set<Tag> tags = ...;
final QLicense license = QLicense.license;
JPAQuery q = new JPAQuery(entityManager).from(license);

for (Tag tag : tags) {
    q.where(license.tags.contains(tag));
}

Collection<License> result = q.listDistinct(license);
Run Code Online (Sandbox Code Playgroud)

我得到以下异常 listDistinct

java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager: 
Exception Description: Syntax error parsing the query [select distinct license
from License license
where ?1 in elements(license.tags)]: unexpected token [in]. …
Run Code Online (Sandbox Code Playgroud)

java jpa eclipselink querydsl

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

在JSF 2复合组件中使用id-attribute和目标

我正在尝试为按钮创建JSF 2.1复合组件:

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:composite="http://java.sun.com/jsf/composite"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
xmlns:c="http://java.sun.com/jstl/core">

    <composite:interface>
        <composite:attribute name="id" required="true" type="java.lang.String" />
        <composite:attribute name="label" required="true" type="java.lang.String" />
        <composite:attribute name="action" method-signature="java.lang.String action()" targets="#{cc.attrs.id}" />
    </composite:interface>

    <composite:implementation>
        <a4j:commandLink id="#{cc.attrs.id}">
            <span style="linkButton"><h:outputText value="#{cc.attrs.label}" /></span>
        </a4j:commandLink>
    </composite:implementation>
</html>
Run Code Online (Sandbox Code Playgroud)

我对此代码的问题是,在呈现页面时它会给出以下异常:

java.lang.ClassCastException: javax.faces.component.UINamingContainer cannot be cast to javax.faces.component.ActionSource2
at com.sun.faces.application.view.FaceletViewHandlingStrategy$MethodRetargetHandlerManager$ActionRegargetHandler.retarget(FaceletViewHandlingStrategy.java:1536)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.retargetMethodExpressions(FaceletViewHandlingStrategy.java:689)
at com.sun.faces.facelets.tag.jsf.CompositeComponentTagHandler.applyNextHandler(CompositeComponentTagHandler.java:201)
at org.richfaces.view.facelets.html.BehaviorsAddingComponentHandlerWrapper.applyNextHandler(BehaviorsAddingComponentHandlerWrapper.java:53)
at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:196)
...
Run Code Online (Sandbox Code Playgroud)

当我用一个定义的String 替换#{cc.attrs.id}in idtargets属性时,myId组件按预期工作,但这使得它不能在同一页面中重复使用,从而消除了创建复合组件的神奇感.

我在这里错过了吗?

jsf el ajax4jsf composite-component jsf-2

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