How can I provide my own @id field using Spring Roo and JPA

白昼怎懂夜的黑 提交于 2019-12-08 21:28:38

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/4226906/how-can-i-provide-my-own-id-field-using-spring-roo-and-jpa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!