如何使用 Spring Roo 和 JPA 提供自己的 @id 字段
我试图让 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来这是 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.