小编Ing*_*her的帖子

将JPA实体命名为"Group"是不合法的吗?

我正在开发一个JEE6应用程序,使用JPA 2.0和Hibernate 3.5.2-Final作为Provider(和MySQL 5.1.41).我的应用服务器是Glassfish V3.0.1.我已经有一个有一些实体和关系的工作CRUD应用程序.

现在我添加了一个名为"Group"的(非常简单的)实体.实体类看起来像这样:

package model
//Imports...
@Entity
public class Group {
  @Id @GeneratedValue
  private Long id;

  @NotNull
  private String name;

  //Getters and Setters
}
Run Code Online (Sandbox Code Playgroud)

当然我也把它添加到了persistence.xml中,就像<class>model.Group</class>.我的persistence.xml在部署时删除并重新创建所有表.

因此,当我部署应用程序时,将生成除我的表组之外的所有实体的表.在hibernate日志中,我发现了以下错误(这不会阻止部署应用程序)

[#|2010-06-30T11:54:29.862+0200|INFO|glassfish3.0.1|org.hibernate.cfg.AnnotationBinder|_ThreadID=11;_ThreadName=Thread-1;|Binding entity from annotated class: model.Group|#]
[#|2010-06-30T11:54:29.862+0200|INFO|glassfish3.0.1|org.hibernate.cfg.annotations.EntityBinder|_ThreadID=11;_ThreadName=Thread-1;|Bind entity model.Group on table Group|#]
[#|2010-06-30T11:54:33.773+0200|SEVERE|glassfish3.0.1|org.hibernate.tool.hbm2ddl.SchemaExport|_ThreadID=11;_ThreadName=Thread-1;|Unsuccessful: create table Group (id bigint not null auto_increment, name varchar(255) not null, primary key (id))|#]
[#|2010-06-30T11:54:33.773+0200|SEVERE|glassfish3.0.1|org.hibernate.tool.hbm2ddl.SchemaExport|_ThreadID=11;_ThreadName=Thread-1;|You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right …
Run Code Online (Sandbox Code Playgroud)

orm hibernate jpa java-ee-6 jpa-2.0

7
推荐指数
2
解决办法
2573
查看次数

JSF 2.0:验证2个InputSecret字段的相等性(确认密码)而不编写代码?

我正在使用JSF 2.0和Glassfish开发纯JavaEE6应用程序.我的JSF实现是Primefaces(除了Glassfish提供的Mojarra).

我想验证JSF表单中2个密码字段的值是否相等.有了Seam,就有了整洁的组件<s:validateEquality for="pw1"/>.我想在没有Seam的情况下做同样的事情,只需使用JSF(或者可能是JSF库的一个组件).到目前为止,我只看到了使用自定义验证器验证表单的示例.但我想比较这些字段而不编写Java代码或Javascript代码.那可能吗?

这与Seam一样:

...
<h:inputSecret id="passwort" value="#{personHome.instance.password}" 
    redisplay="true" required="true">
  <f:validateLength minimum="8"/>
  <a:support event="onblur" reRender="passwortField" bypassUpdates="true" ajaxSingle="true" />
</h:inputSecret>
...    
<h:inputSecret id="passwort2" required="true" redisplay="true">
  <!-- find the JSF2.0-equivalent to this tag: -->
  <s:validateEquality for="passwort"/>
  <a:support event="onblur" reRender="passwort2Field" bypassUpdates="true" ajaxSingle="true" />
</h:inputSecret>
...
Run Code Online (Sandbox Code Playgroud)

jsf java-ee primefaces jsf-2

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

JSF <h:outputFormat>:使用数组值作为参数

在我的JSF2页面上,我正在使用国际化的错误消息.

在我的支持bean中,我将消息放入flash范围:

flash.put("error", exception.getType());
Run Code Online (Sandbox Code Playgroud)

在页面上,此字符串以这种方式翻译:

<h:outputText value="#{bundle[flash.error]}"/>
Run Code Online (Sandbox Code Playgroud)

工作良好.

现在我想能够将(任意数量的)参数放入消息文本中,这些参数将插入到message.properties中i18n属性的占位符中.因此,我将参数作为String数组放入Flash Scope中,如下所示:

//exception.getParameters returns String[]
flash.put("errorParams", exception.getParameters())
Run Code Online (Sandbox Code Playgroud)

现在我也希望能够使用这个String数组作为outputFormat元素的参数,将它们插入到像这样的属性中Welcome, {0} {1}.所以我试图通过使用ui实现这一点:重复:

<h:outputFormat value="#{bundle[flash.error]}" rendered="#{! empty flash.error}" class="invalid">
  <ui:repeat value="#{flash.errorParams}" var="_param">
    <f:param value="#{bundle[_param]}"/>
    <!-- also doesn't work: <f:param value="#{_param}"/>-->
  </ui:repeat>
</h:outputFormat>
Run Code Online (Sandbox Code Playgroud)

不幸的是,param值被忽略,并且i18n-property的占位符没有被替换,因此渲染的输出是Welcome, {0} {1}.当使用"常规"转发器时,将数组元素显示为输出文本,它可以工作.所以outputFormat标签似乎不支持使用repeat作为子元素.该死的,如此接近;)任何人都知道一个很好的方法来做我想要的,或者是否有任何组件库支持这样的东西?

jsf facelets jsf-2

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

将泛型方法的实现移动到抽象超类

编辑:重写了这个问题.添加赏金对我来说很重要.我可以使findByAttributes工作的最终提示(无需在子类中重新实现)将得到我的观点.

在我的应用程序中,我正在使用新的JPA2 Criteria Query进行类型安全的数据库查询.因此,我有一个特性DAO,它应该(重新)可用于我的应用程序中的所有实体.所以这就是我正在使用的当前特征的轮廓如何(有效):

trait DAO[T, K](implicit m: Manifest[T]) {
  @PersistenceContext 
  var em:EntityManager = _

  lazy val cb:CriteriaBuilder = em.getCriteriaBuilder

  def persist(entity: T)
  def update(entity: T)
  def remove(entity: T)
  def findAll(): ArrayList[T]

  // Pair of SingularAttribute and corresponding value
  // (used for queries for multiple attributes)
  type AttributeValuePair[A] = Pair[SingularAttribute[T, A], A]

  // Query for entities where given attribute has given value
  def findByAttribute[A](attribute:AttributeValuePair[A]):ArrayList[T]

  // Query for entities with multiple attributes (like query by example)
  def findByAttributes[A](attributes:AttributeValuePair[_]*):ArrayList[T] 
}
Run Code Online (Sandbox Code Playgroud)

在一个具体的DAO中,我正在扩展这个特性,设置类型和实现方法(删除除了最重要的方法之外的所有方法):

class …
Run Code Online (Sandbox Code Playgroud)

generics scala scala-2.8

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

如何缓存当前会话的Bash完成脚本中使用的变量

在我的Bash Completion文件中,我正在通过外部脚本查找完成字符串,这需要一些时间(1-2秒).由于这些字符串在当前shell运行的其余时间内大部分保持不变,我想缓存它们,并且当下次触发Bash完成时,它应该使用缓存的字符串而不是昂贵的查找,以便它完成第二次运行时立即.

要通过完成文件获得感觉,这是完成文件的重要部分:

getdeployablefiles()
{
  # How can i cache the result of 'pbt getdeployablefiles'
  # for the time the current shell runs? 
  echo `pbt getdeployablefiles`
}

have pbt &&
_pbt_complete()
{
  local cur goals

  COMPREPLY=()
  cur=${COMP_WORDS[COMP_CWORD]}
  goals=$(getdeployablefiles)
  COMPREPLY=( $(compgen -W "${goals}" -- $cur) )
  return 0
} &&
complete -F _pbt_complete pbt
Run Code Online (Sandbox Code Playgroud)

如何在shell会话的其余部分缓存getdeployablefiles的输出?我在这里需要某种全局变量,或者其他一些技巧.

解:

只需要goals非本地人,并询问它是否已设定.最后的剧本:

getdeployablefiles()
{
  echo `pbt getdeployablefiles`
}

have pbt &&
_pbt_complete()
{
  local cur 
  if [ -z "$_pbt_complete_goals" ]; then
    _pbt_complete_goals=$(getdeployablefiles)
  fi

  _pbt_complete_goals=$(getdeployablefiles) …
Run Code Online (Sandbox Code Playgroud)

bash bash-completion

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

使用RNGOM从RelaxNG模式生成对象模型 - 如何开始?

我想用RelaxNG Schema生成一个对象模型.

因此,我想使用RNGOM对象模型/解析器(主要是因为我找不到任何替代方案 - 尽管我甚至不关心解析器编写/生成的语言).现在我从SVN 检查了RNGOM源代码,我不知道如何使用RNGOM,因为没有关于用法的任何信息.

一个有用的提示如何从RNGOM开始 - 一个链接,示例或任何描述,使我不必阅读理解RNGOM的整个源代码 - 将作为答案.更好的是如何使用解析器从RNG文件生成对象模型的简单示例.

更多信息:

我想从以下RelaxNG模式中生成Java类:http://libvirt.org/git/?p = libvirt.git; a = tree; f = docs/schemas; hb = HEAD

我发现Glassfish的人正在使用rngom生成我需要的相同对象模型,但我还不知道他们是如何使用rngom的.

java xsd code-generation relaxng

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

Pytest:仅运行 linter 检查(pytest-flake8),不运行测试

我正在使用pytest-flake8插件来检查我的 Python 代码。每次我这样运行 linting 时:

pytest --flake8
Run Code Online (Sandbox Code Playgroud)

除了 linting 之外,还运行所有测试。但我只想运行 linter 检查。

我如何配置 pytest 以便它只检查代码但跳过所有测试,最好通过命令行(或conftest.py) - 而不必向我的测试添加跳过标记

python pytest

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

多个docker-compose文件-打印生成的合并docker-compose.yml文件

我正在运行Docker撰写合并多个docker-compose-yaml文件,例如:

docker-compose -f docker.compose.yml -f docker-compose.dev.yml -f docker-compose.X.yml -f docker-compose.Y.yml up
Run Code Online (Sandbox Code Playgroud)

因为这对调试很有帮助,是否可以打印docker-compose使用的合并后的docker-compose-yaml文件?

简化示例:

$ cat docker-compose.yml
> version: '3'
> 
> services:
>  nginx:
>     image: nginx:latest

$ cat docker-compose.dev.yml
> version: '3'
> 
> services:
>   nginx:
>     build:
>       context: nginx
>       dockerfile: Dockerfile

# Show merged result 
$PRINT_MERGED_DOCKERFILE_COMMAND -f docker.compose.yml -f docker-compose.dev.yml
> version: '3'
> 
> services:
>   nginx:
>     build:
>       context: nginx
>       dockerfile: Dockerfile
>     image: nginx:latest
Run Code Online (Sandbox Code Playgroud)

docker docker-compose

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

使用 xmlbeans、inst2xsd 和 Maven 从 XML 生成 XSD

我有一个 XML 文件,我想从中生成 XSD 架构,使用xmlbeans,特别是inst2xsd。我想打包脚本,以便它可以通过 Maven 运行。在使用 Maven 安装 xmlbeans 时,我找不到任何有关如何运行 inst2xsd 的文档。这是我pom.xml到目前为止:

<project>
    <modelVersion>4.0.0</modelVersion>

    <groupId>de.wolkenarchitekt</groupId>
    <artifactId>xml-to-xsd</artifactId>
    <version>1</version>

    <dependencies>
        <dependency>
            <groupId>org.apache.xmlbeans</groupId>
            <artifactId>xmlbeans</artifactId>
            <version>3.1.0</version>
        </dependency>
    </dependencies>
</project>
Run Code Online (Sandbox Code Playgroud)

通过mvn install作品安装它。仅供参考 - 对于答案并不重要 - 我通过 Docker 构建它,所以我使用的是 OpenJDK14:

FROM maven:3.6.3-openjdk-14-slim
RUN mkdir -p /opt/workspace
WORKDIR /opt/workspace
COPY pom.xml .
RUN mvn install
Run Code Online (Sandbox Code Playgroud)

现在如何inst2xsd在通过 Maven 安装 xmlbeans 后运行可执行文件?

java xml xsd maven

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

Scala方法,其中第二个参数的类型等于第一个参数的泛型类型的一部分

我想在Scala中创建一个特定的泛型方法.它需要两个参数.第一种是通用Java接口的类型(它来自JPA条件查询).它目前看起来像这样:

def genericFind(attribute:SingularAttribute[Person, _], value:Object) {
  ...
}

// The Java Interface which is the type of the first parameter in my find-method:
public interface SingularAttribute<X, T> extends Attribute<X, T>, Bindable<T>
Run Code Online (Sandbox Code Playgroud)

现在我想实现以下目的: value当前是java.lang.Object类型.但我想让它更具体.值必须与第一个参数中的占位符"_"具有相同的类型(因此代表Java接口中的"T").

这是不可能的,怎么样?

BTW对不起这个愚蠢的问题标题(有什么建议吗?)

编辑: 添加了一个可以使问题更清晰的附加示例:

// A practical example how the Scala method could be called 

// Java class:
public class Person_ {
  public static volatile SingularAttribute<Person, Long> id;
}

// Calling the method from Scala:
genericFind(Person_.id, Long)
Run Code Online (Sandbox Code Playgroud)

generics scala scala-2.8

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