问题
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