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.
Id is required by JPA, but it is not required that the Id specified in your mapping match the Id in your database. For instance you can map a table with no id to a jpa entity. To do it just specify that the "Jpa Id" is the combination of all columns.
@Id annotation is the JPA is used for making specific variable primary key.
The most straightforward way is to define a generated ID in a JPA entity is to annotate a field with the @Id and @GeneratedValue annotations. We don't even need to specify any parameters for the @GeneratedValue .
Spring Data JPA aims to significantly improve the implementation of data access layers by reducing the effort to the amount that's actually needed. As a developer you write your repository interfaces, including custom finder methods, and Spring will provide the implementation automatically.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With