相关疑难解决方法(0)

有没有办法扫描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万
查看次数

通过在某个包中添加所有类,在Hibernate中添加带注释的类.JAVA

有没有办法循环(例如,通过)所有类在一些包中? 我必须addAnnotatedClass(Class c)AnnotationConfiguration.这样做:

    AnnotationConfiguration annotationConfiguration.addAnnotatedClass(AdditionalInformation.class);
    annotationConfiguration.addAnnotatedClass(AdditionalInformationGroup.class);
    annotationConfiguration.addAnnotatedClass(Address.class);
    annotationConfiguration.addAnnotatedClass(BankAccount.class);
    annotationConfiguration.addAnnotatedClass(City.class);
    //et cetera
Run Code Online (Sandbox Code Playgroud)

我的所有桌子都是包装好的Tables.Informations.

java hibernate

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

标签 统计

java ×2

hibernate ×1

jpa ×1

persistence.xml ×1