ORM在部署的WAR文件中被忽略。

huangapple 未分类评论42阅读模式
英文:

ORM in deployed WAR file is being ignored

问题

我所使用的设置是,我正在使用Maven构建一个Spring API项目,并生成一个.WAR文件。这个WAR文件正在部署到一个Tomcat服务器上。我的设置在Eclipse中本地工作时没有任何问题,可以调用正确的查询等。然而,当我尝试部署到Tomcat服务器时,出现以下错误:

Caused by: org.springframework.data.mapping.PropertyReferenceException: No property findDetails found for type EmployeeInfo!
    at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:94)
    ...

我不确定是否缺少了某些必要的连接,或者可能需要进行某些设置。任何帮助都受欢迎 - 我已经包含了尽可能多的相关文件,但如果需要其他内容,请告诉我,我也会上传。

EmployeeInfoRepository

@Repository
public interface EmployeeInfoRepository extends JpaRepository<EmployeeInfo, Integer> {
    @Query(nativeQuery = true)
    public List<EmployeeInfo> findDetails(@Param("id") String id);
}

orm.xml(请注意,它位于src/main/resources/META-INF/目录下)

<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings version="2.0" xmlns="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm
    http://java.sun.com/xml/ns/persistence/orm_2_0.xsd">
    <named-native-query name="EmployeeInfo.findDetails" result-class="com.place.thing.model.EmployeeInfo">
        <query>SELECT ... </query>
    </named-native-query>
</entity-mappings>

EmployeeInfoController

@GetMapping("/intake/{id}")
public ResponseEntity<EmployeeIntakeInfoResponse> getEmployeeInfo(@PathVariable(value = "id") String id) throws ResourceNotFoundException {
    List<EmployeeInfo> result = intakeFormRepo.findDetails(id);

    if (result.size() != 1) {
        throw new ResourceNotFoundException("Error Message Here");
    }

    return ResponseEntity.ok().body(new EmployeeInfoResponse(result.get(0)));
}

(请注意,上述代码是根据您提供的内容进行的翻译,可能需要根据实际情况进行调整。)

英文:

The setup I have is that I am using Maven to build a Spring API project and generating a .WAR file. This war file is being deployed to a Tomcat server. My setup works locally in Eclipse with no issues or problems, and calls the correct queries/etc. However when I attempt to deploy it to the Tomcat server, I get the following error:

        Caused by: org.springframework.data.mapping.PropertyReferenceException: No property findDetails found for type EmployeeInfo!
            at org.springframework.data.mapping.PropertyPath.&lt;init&gt;(PropertyPath.java:94)
            at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:382)
            at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:358)
            at org.springframework.data.mapping.PropertyPath.lambda$from$0(PropertyPath.java:311)
            at java.util.concurrent.ConcurrentMap.computeIfAbsent(ConcurrentMap.java:324)
            at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:293)
            at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:276)
            at org.springframework.data.repository.query.parser.Part.&lt;init&gt;(Part.java:81)
            at org.springframework.data.repository.query.parser.PartTree$OrPart.lambda$new$0(PartTree.java:250)
            at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
            at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
            at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948)
            at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
            at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
            at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
            at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
            at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:566)
            at org.springframework.data.repository.query.parser.PartTree$OrPart.&lt;init&gt;(PartTree.java:251)
            at org.springframework.data.repository.query.parser.PartTree$Predicate.lambda$new$0(PartTree.java:380)
            at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
            at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
            at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948)
            at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
            at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
            at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
            at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
            at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:566)
            at org.springframework.data.repository.query.parser.PartTree$Predicate.&lt;init&gt;(PartTree.java:381)
            at org.springframework.data.repository.query.parser.PartTree.&lt;init&gt;(PartTree.java:93)
            at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.&lt;init&gt;(PartTreeJpaQuery.java:76)
            ... 96 more

I am not sure if we are missing something required to bridge the connection, or there is maybe a setting that is needed. Any assistance is welcome - I have included as many relevant files as I can think of, but let me know if anything else might be required and I will upload it too.

EmployeeInfoRepository

@Repository
public interface EmployeeInfoRepository extends JpaRepository&lt;EmployeeInfo, Integer&gt; {
@Query(nativeQuery = true)
    public List&lt;EmployeeInfo&gt; findDetails(@Param(&quot;id&quot;) String id);
}

orm.xml (please note, it is located in src/main/resources/META-INF/)

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;entity-mappings version=&quot;2.0&quot; xmlns=&quot;http://java.sun.com/xml/ns/persistence/orm&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/persistence/orm
    http://java.sun.com/xml/ns/persistence/orm_2_0.xsd &quot;&gt;
&lt;named-native-query name=&quot;EmployeeInfo.findDetails&quot; result-class=&quot;com.place.thing.model.EmployeeInfo&quot;&gt;
	&lt;query&gt;SELECT ...  &lt;/query&gt;
&lt;/named-native-query&gt;
&lt;/entity-mappings&gt;

EmployeeInfoController

    @GetMapping(&quot;/intake/{id}&quot;)
public ResponseEntity&lt;EmployeeIntakeInfoResponse&gt; getEmployeeInfo(@PathVariable(value = &quot;id&quot;) String id) throws ResourceNotFoundException {
List&lt;EmployeeInfo&gt; result = intakeFormRepo.findDetails(id);

if (result.size() != 1) {
    throw new ResourceNotFoundException(&quot;Error Message Here&quot;);
}

return ResponseEntity.ok().body(new EmployeeInfoResponse(result.get(0)));
}

huangapple
  • 本文由 发表于 2020年7月25日 04:28:53
  • 转载请务必保留本文链接:https://java.coder-hub.com/63081012.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定