Cassandra DataStax @Entity-Naterated类必须至少有一个属性定义

发布于 2025-01-30 03:30:51 字数 743 浏览 6 评论 0原文

我在执行MVN清洁软件包/MVN清洁安装时使用了下面的实体类Java驱动程序4.1.x

package com.xyz;

import com.datastax.oss.driver.api.mapper.annotations.CqlName;
import com.datastax.oss.driver.api.mapper.annotations.Entity;
import com.datastax.oss.driver.api.mapper.annotations.PartitionKey;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Entity
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class Xyz {

    @PartitionKey
    @CqlName("id")
    private Integer id;

    @CqlName("name")
    private String name;

    @CqlName("description")
    private String description;
}

,以下是错误(未编译实体类)

[xyz] @Entity-nartotation类必须至少具有一个定义的属性。

I have below Entity class used Datastax java driver 4.1.x

package com.xyz;

import com.datastax.oss.driver.api.mapper.annotations.CqlName;
import com.datastax.oss.driver.api.mapper.annotations.Entity;
import com.datastax.oss.driver.api.mapper.annotations.PartitionKey;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Entity
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class Xyz {

    @PartitionKey
    @CqlName("id")
    private Integer id;

    @CqlName("name")
    private String name;

    @CqlName("description")
    private String description;
}

While doing mvn clean package/mvn clean install, getting below error (not compiled Entity class)

[Xyz] @Entity-annotated class must have at least one property defined.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

悸初 2025-02-06 03:30:51

对我有用的解决方案是在我的POM中包含以下配置:

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                            <version>${lombok.version}</version>
                        </path>
                        <path>
                            <groupId>com.datastax.oss</groupId>
                            <artifactId>java-driver-mapper-processor</artifactId>
                            <version>${cassandra-java-driver-core.version}</version>
                        </path>
                    </annotationProcessorPaths>
                </configuration>
            </plugin>

最好将@data用于可变的对象或@Value作为不变的类型。
随着我在我的POM中添加上述内容,这对我有用:
您可以在DataStax文档中找到有关此信息的更多信息:
/EN/DEVELECTER/JAVA-DRIVER/4.10/MANUAL/MAPPER/CONFIG/LOMBOK/

@Entity(defaultKeyspace = "mykeyspace")
@CqlName("tableName")
@Data
public final class SomeEntity {

    @PartitionKey
    @CqlName("theid")
    private String someId;

    @CqlName("someUdtTableColumn")
    private tableColumn thetableProperty;

}

The solution that worked for me is to include the below config in my pom:

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                            <version>${lombok.version}</version>
                        </path>
                        <path>
                            <groupId>com.datastax.oss</groupId>
                            <artifactId>java-driver-mapper-processor</artifactId>
                            <version>${cassandra-java-driver-core.version}</version>
                        </path>
                    </annotationProcessorPaths>
                </configuration>
            </plugin>

It may be better to use @Data for mutable objects or @Value for immutable types.
With the addition of the above in my pom, this worked for me:
You can find more about this in the datastax documentation:
https://docs.datastax.com/en/developer/java-driver/4.10/manual/mapper/config/lombok/

@Entity(defaultKeyspace = "mykeyspace")
@CqlName("tableName")
@Data
public final class SomeEntity {

    @PartitionKey
    @CqlName("theid")
    private String someId;

    @CqlName("someUdtTableColumn")
    private tableColumn thetableProperty;

}

将军与妓 2025-02-06 03:30:51

在Gradle中,似乎按顺序处理注释处理器。我在Scylla注释处理器之前定义了Lombok注释处理器,并且它起作用。

作品:

//lombok
annotationProcessor "org.projectlombok:lombok:$lombokVersion"

//Scylla
annotationProcessor "com.scylladb:java-driver-mapper-processor:$scyllaDriverVersion"

不起作用:

//Scylla
annotationProcessor "com.scylladb:java-driver-mapper-processor:$scyllaDriverVersion"

//lombok
annotationProcessor "org.projectlombok:lombok:$lombokVersion"

In gradle, it seems like the annotation processors are processed in sequence. I defined the lombok annotation processor before the scylla annotation processor and it worked.

Works:

//lombok
annotationProcessor "org.projectlombok:lombok:$lombokVersion"

//Scylla
annotationProcessor "com.scylladb:java-driver-mapper-processor:$scyllaDriverVersion"

Doesn't work:

//Scylla
annotationProcessor "com.scylladb:java-driver-mapper-processor:$scyllaDriverVersion"

//lombok
annotationProcessor "org.projectlombok:lombok:$lombokVersion"
半窗疏影 2025-02-06 03:30:51

我面临同样的问题。我正在使用DataStax驱动程序4.15.0。注释处理在Intellijl中启用。看起来Lombok和DataStax存在问题。 Intellij可能是原因之一。我删除了以下内容
@getter
@setter
@noargsconstructor
@AllargSconstructor

生成的香草获取器,固定器和构造函数,并且有效!

I faced the same issue. I am using Datastax driver 4.15.0. Annotation processing is enabled in Intellijl. Looks like there is an issue with Lombok and datastax. Intellij can be one of the reasons. I removed the following
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor

Generated vanilla getters,setters and constructors and it worked!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文