如何使用 Spring Roo 和 JPA 提供自己的 @id 字段

发布于 2024-10-03 17:57:34 字数 564 浏览 0 评论 0原文

我试图让 Spring Roo 使用我自己的 @Id 字段而不是生成一个。

@Entity
...
@RooEntity
@Table(name = "usr")
public class User {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "usr_id")
    private Integer id;
    ...
    public Integer getId() { return id; }
    public void setId(Integer id) { this.id = id }
    ...
}

Roo 仍然在 User_Roo_Entity.aj 中创建以下内容:

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "_id")
private Long User._id;

如何让它确认我的 @Id 字段?我想指定我自己的发电机等。

I am trying to get Spring Roo to use my own @Id field instead of generating one.

@Entity
...
@RooEntity
@Table(name = "usr")
public class User {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "usr_id")
    private Integer id;
    ...
    public Integer getId() { return id; }
    public void setId(Integer id) { this.id = id }
    ...
}

Roo still creates the following in User_Roo_Entity.aj:

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "_id")
private Long User._id;

How can I get it to acknowledge my @Id field? I want to specify my own generator etc.

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

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

发布评论

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

评论(1

奢华的一滴泪 2024-10-10 17:57:34

看起来这是 Spring Roo 1.1.0.RELEASE 中的一个错误。我将 @Id 更改为 @javax.persistence.Id 并且它有效。显式导入 javax.persistence.Id 也可以(而不仅仅是 javax.persistence.*)。我在 IntelliJ 中优化了导入,因此第一个选项可能是最好的解决方法。

Looks like this is a bug in Spring Roo 1.1.0.RELEASE. I changed @Id to @javax.persistence.Id and it works. Explicitly importing javax.persistence.Id also works (instead of just javax.persistence.*). I have optimize imports on in IntelliJ so the first option is probably the best workaround.

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