相关疑难解决方法(0)

JPA 2.0:自动从不同的jar*向PersistenceUnit*添加实体类

我有一个maven构建的基于CDI的Java SE应用程序,它有一个核心模块和其他模块.
核心有persistence.xml一些实体.模块有其他实体.

如何将实体添加到持久性单元的聚光灯下?

我已阅读Hibernate手册,http://docs.jboss.org/hibernate/stable/entitymanager/reference/en/html/configuration.html#setup-configuration-packaging

我也看过这些问题

我正在寻找一个解决方案,其中Hibernate将扫描所有加载的类,或者,将从其他罐中获取一些配置文件(例如CDI所做的beans.xml).

我的应用程序不使用Spring.我不坚持可移植性 - 我会坚持使用Hibernate.

  • 有一些这样的解决方案吗?
  • 有没有办法从程序创建PU persistence.xml并向其添加类?
  • EntityManagerFactory可以在创建后添加@Entity类吗?

更新:我发现org.?hibernate.?ejb.?Ejb3Configuration:

public Ejb3Configuration configure(String persistenceUnitName, Map integration)  
Run Code Online (Sandbox Code Playgroud)

http://docs.jboss.org/hibernate/entitymanager/3.6/javadocs/

configuration entity entities hibernate jpa-2.0

38
推荐指数
4
解决办法
3万
查看次数

有没有办法扫描JPA实体不要在persistence.xml文件中声明持久化类?

我想利用JPA @Entity注释不要将类实体声明为J2SE persistence.xml文件.我想避免的:

<persistence-unit name="test" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <class>com.mycompany.entities.Class1</class>
    <class>com.mycompany.entities.Class2</class>
    <class>com.mycompany.entities.Class3</class>
</persistence-unit>
Run Code Online (Sandbox Code Playgroud)

这是我的实际persistence.xml看起来很像

    <persistence-unit name="test" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <properties>
        <!-- Scan for annotated classes and Hibernate mapping XML files -->
        <property name="hibernate.archive.autodetection" value="class, hbm" />
        <property name="hibernate.cache.use_second_level_cache" value="false" />
        <property name="hibernate.cache.use_query_cache" value="false" />
        <property name="hibernate.hbm2ddl.auto" value="create-drop" />
    </properties>
</persistence-unit>
Run Code Online (Sandbox Code Playgroud)

是否有一种标准方法可以在JAR模块中扫描persistence.xml文件中的JPA实体?是否有一种不标准的Hibernate方法从JAR模块中扫描persistence.xml文件中的JPA实体?

java jpa persistence.xml

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

如何在JPA 2.0中自动检测实体

我很确定我过去在JPA 2.0中使用了@Entity注释的bean的某种自动检测,但我无法弄清楚如何.你如何做而不是将每个bean列在classpersistence.xml 中的XML元素中?

java spring jpa java-ee

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

每个Entity Bean都必须在persistence.xml中注册吗?

我正在使用Eclipse Facets进行JPA 2.0和Hibernate 4.2实现.我想我记得在之前的项目中我不必在persistence.xml中注册实体Bean.我错了吗?

使用@Entity注释POJO(在本例中为Pub.java)将在Eclipse标记/问题视图中引发以下错误:

Class "com.jacky.webapp.model.Pub" is managed, but is not listed in the persistence.xml file    Pub.java    /webapp/src/main/java/com/jacky/webapp/model    
Run Code Online (Sandbox Code Playgroud)

任何线索?谢谢.

eclipse hibernate jpa jboss-tools

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

Eclipse中的JPA项目问题 - 类注释中的错误@Entity:表"xxx"无法解析

我正在尝试在Eclipse(Indigo)中创建简单的EJB + JPA项目.我创建了新的EJB项目,其中:

  • 目标:现有的Glassfish服务器
  • 配置:EJB模块+ GlassFish部署描述符文件+ Java + JPA在窗口JPA Facet我声明连接到postgres db(ping成功)

我在尝试定义实体时遇到问题:表"Employee"无法解析.我添加了带有指定名称参数的@Table注释,但这不起作用.我的persistence.xml文件:

    <persistence-unit name="pu_name">
    <jta-data-source>jdbc/baza1Postgres</jta-data-source>
</persistence-unit>
Run Code Online (Sandbox Code Playgroud)

在glassfish中,我定义了名为JDBC资源的JDBC资源:"jdbc/baza1Postgres
"如果我的表存在,"eclipse如何知道"?还有什么我应该配置?

eclipse postgresql ejb jpa glassfish

10
推荐指数
3
解决办法
4万
查看次数

Hibernate Envers因@Converter和AttributeConverter失败(JPA 2.1)

我正在使用带有Envers的Hibernate 4.3.4和MySql 5.6.

如果没有JPA 2.1转换器,Party下面的实体就会失败Configuration.buildSessionFactory(),因为Hibernate不知道如何处理Name类:

@Entity
@Audited
public class Party
    {
    protected Name name;
    ...
    }
Run Code Online (Sandbox Code Playgroud)

例外是:

org.hibernate.MappingException: 
  Could not determine type for: 
    ModuloADM.Party.Name, 
    at table: Party, for columns: [org.hibernate.mapping.Column(name)]
Run Code Online (Sandbox Code Playgroud)

要解决此问题,我然后添加此转换器:

@Converter (autoApply=true)
public class NametoStringConverter
      implements AttributeConverter<Name, String>
    { ... }
Run Code Online (Sandbox Code Playgroud)

现在异常变为:

org.hibernate.MappingException: 
  Could not determine type for: 
    BasicType adapter for AttributeConverter<Name,String>, 
    at table: History_Party, for columns: [org.hibernate.mapping.Column(name)]
Run Code Online (Sandbox Code Playgroud)

现在,在Party实体的Envers审核表中失败了.请注意,这History_Party是审计表的名称,由选择config.setProperty("org.hibernate.envers.audit_table_prefix", "History_").

完整的堆栈跟踪是:

org.hibernate.MappingException: 
  Could not determine type for: 
    BasicType adapter …
Run Code Online (Sandbox Code Playgroud)

java hibernate jpa hibernate-envers jpa-2.1

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

SpringBoot“不是一个实体”

我是 Hibernate 和 SpringBoot 的新手。我的项目涉及一个搜索引擎,该搜索引擎由 2 个独立模块 + 1 个两者共用的基本模块(类IndexSetup所在的位置)组成。

有一个用于索引的模块 (JavaFx),另一个用于通过 Web 浏览器进行搜索 (Spring Boot)。

索引模块涉及一个“IndexSetup”类,其中包含有关如何/应索引什么的详细信息:

@Entity
@Table(name = "IndexSetups")
@Access(AccessType.PROPERTY)
public class IndexSetup {
  private final SimpleIntegerProperty id = new SimpleIntegerProperty();

  @Id
  @GeneratedValue(strategy = GenerationType.AUTO) // For H2 AUTO is required to auto increment the id
  public int getId() {
      return id.get();
  }

  //... other properties, getters and setters

 }
Run Code Online (Sandbox Code Playgroud)

所以它工作得很好,数据被索引并且可以通过索引模块内的搜索方法检索。

但是,当我运行 Spring Boot 服务器并执行相同的搜索时,我得到 java.lang.IllegalArgumentException: Not anEntity: class my.package.IndexSetup

顺便说一句,没有构建错误,并且在模块成为父 pom 项目的一部分之前,它们与子文件夹中的服务器类位于同一项目中,并且它可以工作。为了方便开发过程,我决定将它们分开,并在生产中提供两个独立的模块。

那么,当所有内容都在同一个 Netbeans 项目下并且现在模块位于 …

java hibernate spring-boot

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