I have an Entity which for a number of reasons ( Why should anybody put annotations on the getters or setters when using JPA to map the classes? ) we are annotating the getter method instead of the field:
protected Long id;
...
@Id
@GeneratedValue(...)
@SequenceGenerator(...)
@Column(name = "id")
public Long getId()
{
return id;
}
public void setId(Long id)
{
this.id = id;
}
When calling:
javers.findChanges(QueryBuilder.byInstanceId(5, MyModel.class).build())
JaVers is throwing the following exception:
JaversException: ENTITY_WITHOUT_ID Class 'com.myproject.model.MyModel' mapped as Entity has no Id property. Use @Id annotation to mark unique and not-null Entity identifier.
Is it supported?
JaVers do supports mapping on getters & setters, it's called BEAN mapping style, see: http://javers.org/documentation/domain-configuration/#property-mapping-style .
By default, FIELD mapping is used but you can switch to BEAN as follows:
Javers javers = JaversBuilder
.javers()
.withMappingStyle(MappingStyle.BEAN)
.build();
我已经将javers.mappingStyle=BEAN
设置为 application.properties 并且它有效。
I stand corrected. JaVers supports both Bean and field Mapping style as per documentation http://javers.org/documentation/domain-configuration/#property-mapping-style . Still, when using the BEAN mapping as suggested, it is still not working. Maybe it is conflicting with other annotations? Here is my code and where Ive placed the JaVers @Id
I changed the MappingStyle to BEAN style and still it doesnt work. Here is the JaVers @Id on my getter field:
@Id
@GeneratedValue(generator = "...")
@SequenceGenerator(...
@Column(name = "id")
@org.javers.core.metamodel.annotation.Id
public Long getId()
{
return id;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.