Java gradle缺少什么来映射hibernate?

Java gradle缺少什么来映射hibernate?,java,hibernate,gradle,Java,Hibernate,Gradle,我对我的java项目进行了单元测试 我的代码使用hibernate 当我使用junit运行测试时,一切都通过了 当我使用gradle运行测试时,我得到一个映射错误: Caused by: org.hibernate.MappingException: Unknown entity: linqmap.users.interfaces.model.UserRecord 班级: @Entity @Table(name = "users") public class UserRecord imple

我对我的java项目进行了单元测试

我的代码使用hibernate

当我使用junit运行测试时,一切都通过了

当我使用gradle运行测试时,我得到一个映射错误:

Caused by: org.hibernate.MappingException: Unknown entity: linqmap.users.interfaces.model.UserRecord
班级:

@Entity
@Table(name = "users")

public class UserRecord implements Serializable {

    private static final long serialVersionUID = 1L;
    public static short CLASS_VERSION = 3;

    @Transient
    public short objectVersion = CLASS_VERSION;

    @Id @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name = "id")
    public long ID;

    @Column(name = "user_name")
    public String userName;

    @Column(name = "email")
    public String email;

    @Column(name = "full_name") // will be deprecated in the future
    public String fullName;

    @Column(name = "password")
    public String password;
和一个配置文件:

<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
    http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
    version="1.0">

    <persistence-unit name="UsersDB">

        <!-- The provider only needs to be set if you use several JPA providers <provider>org.hibernate.ejb.HibernatePersistence</provider> -->

        <properties>
            <!-- Scan for annotated classes and Hibernate mapping XML files -->
            <property name="hibernate.archive.autodetection" value="class, hbm" />

            <!-- SQL stdout logging <property name="hibernate.show_sql" value="true"/> <property name="hibernate.format_sql" value="true"/> 
                <property name="use_sql_comments" value="true"/> -->

            <property name="hibernate.connection.driver_class" value="org.postgresql.Driver" />
            <property name="hibernate.connection.url" value="dbc:postgresql://localhost:9992/israel" />


gradle可能缺少什么?

我认为问题不在于gradle。事实上,JPA规范愚蠢地要求实体的类与persistence.xml文件位于同一jar/目录中。由于Gradle没有将“已编译”资源存储在与已编译类相同的输出目录中,Hibernate找不到映射的实体

将这一行添加到gradle构建中,可能会很好

sourceSets.main.output.resourcesDir = sourceSets.main.output.classesDir

hibernate的人不知道这个问题吗?看起来像个白痴。。。(顺便说一句,非常感谢您提供的解决方案!)在Gradle 5.x中,您需要使用
sourceset.main.java.outputDir
而不是
sourceset.main.output.classesDir
参见:SourceSetOutput-Gradle DSL 5.5版