无法导入javax.persistence.MapsId。

huangapple go评论83阅读模式
英文:

Cannot import javax.persistence.MapsId

问题

使用 Spring Data JPA,我想在一个实体的代码中使用 @MapsId 注解。

尽管我在实体中添加了 import javax.persistence.*;

但我遇到了以下编译错误:

找不到符号
[ERROR]   符号:   方法 name()
[ERROR]   位置: @interface javax.persistence.MapsId

我的 pom.xml 文件如下:

<?xml version="1.0" encoding="UTF-8"?>
<project
    xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    ...

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
			<version>2.3.4.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
			<version>2.3.4.RELEASE</version>
        </dependency>
        <dependency>
			<groupId>org.postgresql</groupId>
			<artifactId>postgresql</artifactId>
			<version>9.4.1210</version>
		</dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
			<version>2.3.4.RELEASE</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>
英文:

I use Spring Data JPA and I would like to use the @MapsId annotation in the code of one of my entities

Although I put import javax.persistence.*; in my entity

I have the following compilation error :

cannot find symbol
[ERROR]   symbol:   method name()
[ERROR]   location: @interface javax.persistence.MapsId

My pom.xml is

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project
    xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
    xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
    ...

    &lt;dependencies&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
            &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
			&lt;version&gt;2.3.4.RELEASE&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
            &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
			&lt;version&gt;2.3.4.RELEASE&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
			&lt;groupId&gt;org.postgresql&lt;/groupId&gt;
			&lt;artifactId&gt;postgresql&lt;/artifactId&gt;
			&lt;version&gt;9.4.1210&lt;/version&gt;
		&lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
            &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
            &lt;scope&gt;test&lt;/scope&gt;
			&lt;version&gt;2.3.4.RELEASE&lt;/version&gt;
        &lt;/dependency&gt;
    &lt;/dependencies&gt;
    &lt;build&gt;
        &lt;plugins&gt;
            &lt;plugin&gt;
                &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
            &lt;/plugin&gt;
        &lt;/plugins&gt;
    &lt;/build&gt;
&lt;/project&gt;

答案1

得分: 1

你正在使用 @MapsId(name = "something"),但在 @MapsId 上不存在 name

请改用 value@MapsId(value = "something"),或者简单地使用 @MapsId("something")

英文:

You are using @MapsId(name = &quot;something&quot;), but name doesn't exist on @MapsId.

Use value instead: @MapsId(value = &quot;something&quot;), or simply @MapsId(&quot;something&quot;)

huangapple
  • 本文由 发表于 2020年10月15日 06:26:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/64362334.html
匿名

发表评论

匿名网友

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

确定