AuditingEntityListener is not working for the entity that extends another abstract entity in spring jpa
up vote
0
down vote
favorite
I have used the @CreatedBy, @CreatedDate, @LastModifiedBy, and @LastModifiedDate annotation on their respective fields. By using @MappedSuperclass,@EntityListeners i able to persist above columns.
But this is not working for the below case:
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public abstract class Auditable<U> {
@CreatedBy
protected U createdBy;
@CreatedDate
@Temporal(TIMESTAMP)
protected Date creationDate;
@LastModifiedBy
protected U lastModifiedBy;
@LastModifiedDate
@Temporal(TIMESTAMP)
protected Date lastModifiedDate;
}
@Entity
@Table(name = "tabel1")
@PrimaryKeyJoinColumn(name = "ID")
class A extends B {
@Column(name = "NAME1", nullable = false)
private String name1;
@Column(name = "CONTENT1", nullable = false)
private String content1;
}
@Entity
@Table(name = "tabel2")
public abstract class B extends Auditable{
@Id
@GeneratedValue
@Column(name = "ID", nullable = false)
private int id;
@Column(name = "NAME", nullable = false)
private String name;
@Column(name = "CONTENT", nullable = false)
private String content;
}
AuditorAwareImpl.java
public class AuditorAwareImpl implements AuditorAware<String>
{
@Override
public Optional<String> getCurrentAuditor()
{
return Optional.ofNullable("Saravanan");
}
}
JpaAuditConfiguration.java
@Configuration
@EnableJpaAuditing(auditorAwareRef = "auditorProvider")
public class JpaAuditConfiguration
{
@Bean
public AuditorAware<String> auditorProvider()
{
return new AuditorAwareImpl();
}
}
In the case, Entity B is populated with audit columns. But Entity A is not. Is there a way to populate Entity A or did i missed anything here..??
spring spring-mvc spring-boot spring-data-jpa
add a comment |
up vote
0
down vote
favorite
I have used the @CreatedBy, @CreatedDate, @LastModifiedBy, and @LastModifiedDate annotation on their respective fields. By using @MappedSuperclass,@EntityListeners i able to persist above columns.
But this is not working for the below case:
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public abstract class Auditable<U> {
@CreatedBy
protected U createdBy;
@CreatedDate
@Temporal(TIMESTAMP)
protected Date creationDate;
@LastModifiedBy
protected U lastModifiedBy;
@LastModifiedDate
@Temporal(TIMESTAMP)
protected Date lastModifiedDate;
}
@Entity
@Table(name = "tabel1")
@PrimaryKeyJoinColumn(name = "ID")
class A extends B {
@Column(name = "NAME1", nullable = false)
private String name1;
@Column(name = "CONTENT1", nullable = false)
private String content1;
}
@Entity
@Table(name = "tabel2")
public abstract class B extends Auditable{
@Id
@GeneratedValue
@Column(name = "ID", nullable = false)
private int id;
@Column(name = "NAME", nullable = false)
private String name;
@Column(name = "CONTENT", nullable = false)
private String content;
}
AuditorAwareImpl.java
public class AuditorAwareImpl implements AuditorAware<String>
{
@Override
public Optional<String> getCurrentAuditor()
{
return Optional.ofNullable("Saravanan");
}
}
JpaAuditConfiguration.java
@Configuration
@EnableJpaAuditing(auditorAwareRef = "auditorProvider")
public class JpaAuditConfiguration
{
@Bean
public AuditorAware<String> auditorProvider()
{
return new AuditorAwareImpl();
}
}
In the case, Entity B is populated with audit columns. But Entity A is not. Is there a way to populate Entity A or did i missed anything here..??
spring spring-mvc spring-boot spring-data-jpa
Is class A defined as entity?
– Periklis Douvitsas
Nov 19 at 15:10
yes, i edited the code also
– Saravanan
Nov 20 at 4:42
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have used the @CreatedBy, @CreatedDate, @LastModifiedBy, and @LastModifiedDate annotation on their respective fields. By using @MappedSuperclass,@EntityListeners i able to persist above columns.
But this is not working for the below case:
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public abstract class Auditable<U> {
@CreatedBy
protected U createdBy;
@CreatedDate
@Temporal(TIMESTAMP)
protected Date creationDate;
@LastModifiedBy
protected U lastModifiedBy;
@LastModifiedDate
@Temporal(TIMESTAMP)
protected Date lastModifiedDate;
}
@Entity
@Table(name = "tabel1")
@PrimaryKeyJoinColumn(name = "ID")
class A extends B {
@Column(name = "NAME1", nullable = false)
private String name1;
@Column(name = "CONTENT1", nullable = false)
private String content1;
}
@Entity
@Table(name = "tabel2")
public abstract class B extends Auditable{
@Id
@GeneratedValue
@Column(name = "ID", nullable = false)
private int id;
@Column(name = "NAME", nullable = false)
private String name;
@Column(name = "CONTENT", nullable = false)
private String content;
}
AuditorAwareImpl.java
public class AuditorAwareImpl implements AuditorAware<String>
{
@Override
public Optional<String> getCurrentAuditor()
{
return Optional.ofNullable("Saravanan");
}
}
JpaAuditConfiguration.java
@Configuration
@EnableJpaAuditing(auditorAwareRef = "auditorProvider")
public class JpaAuditConfiguration
{
@Bean
public AuditorAware<String> auditorProvider()
{
return new AuditorAwareImpl();
}
}
In the case, Entity B is populated with audit columns. But Entity A is not. Is there a way to populate Entity A or did i missed anything here..??
spring spring-mvc spring-boot spring-data-jpa
I have used the @CreatedBy, @CreatedDate, @LastModifiedBy, and @LastModifiedDate annotation on their respective fields. By using @MappedSuperclass,@EntityListeners i able to persist above columns.
But this is not working for the below case:
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public abstract class Auditable<U> {
@CreatedBy
protected U createdBy;
@CreatedDate
@Temporal(TIMESTAMP)
protected Date creationDate;
@LastModifiedBy
protected U lastModifiedBy;
@LastModifiedDate
@Temporal(TIMESTAMP)
protected Date lastModifiedDate;
}
@Entity
@Table(name = "tabel1")
@PrimaryKeyJoinColumn(name = "ID")
class A extends B {
@Column(name = "NAME1", nullable = false)
private String name1;
@Column(name = "CONTENT1", nullable = false)
private String content1;
}
@Entity
@Table(name = "tabel2")
public abstract class B extends Auditable{
@Id
@GeneratedValue
@Column(name = "ID", nullable = false)
private int id;
@Column(name = "NAME", nullable = false)
private String name;
@Column(name = "CONTENT", nullable = false)
private String content;
}
AuditorAwareImpl.java
public class AuditorAwareImpl implements AuditorAware<String>
{
@Override
public Optional<String> getCurrentAuditor()
{
return Optional.ofNullable("Saravanan");
}
}
JpaAuditConfiguration.java
@Configuration
@EnableJpaAuditing(auditorAwareRef = "auditorProvider")
public class JpaAuditConfiguration
{
@Bean
public AuditorAware<String> auditorProvider()
{
return new AuditorAwareImpl();
}
}
In the case, Entity B is populated with audit columns. But Entity A is not. Is there a way to populate Entity A or did i missed anything here..??
spring spring-mvc spring-boot spring-data-jpa
spring spring-mvc spring-boot spring-data-jpa
edited Nov 21 at 13:09
asked Nov 19 at 13:24
Saravanan
4,88935118196
4,88935118196
Is class A defined as entity?
– Periklis Douvitsas
Nov 19 at 15:10
yes, i edited the code also
– Saravanan
Nov 20 at 4:42
add a comment |
Is class A defined as entity?
– Periklis Douvitsas
Nov 19 at 15:10
yes, i edited the code also
– Saravanan
Nov 20 at 4:42
Is class A defined as entity?
– Periklis Douvitsas
Nov 19 at 15:10
Is class A defined as entity?
– Periklis Douvitsas
Nov 19 at 15:10
yes, i edited the code also
– Saravanan
Nov 20 at 4:42
yes, i edited the code also
– Saravanan
Nov 20 at 4:42
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
I added @Entity annotation to your classes:
@Entity
public class A extends B {
@Id
@GeneratedValue
private Integer id;
private String name;
private String content;
}
@Entity
public class B extends Auditable<String> {
@Id
@GeneratedValue
private Integer id;
private String name;
private String content;
}
Persistence config class (for Spring Boot):
@Configuration
@EnableJpaAuditing
public class PersistenceConfig {
}
Everything works perfectly!
Thanks for your reply.. But for me A entity is not populating with the audit fields..I have updated other classes also.. could you pls verify it
– Saravanan
Nov 20 at 4:52
I have published my source code here. Hope it might be useful for you.
– huytmb
Nov 20 at 7:35
when i looked at my code B entity declared as abstract here... I have modified my code above. Could you please have a look at that huymb..?
– Saravanan
Nov 21 at 9:44
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
I added @Entity annotation to your classes:
@Entity
public class A extends B {
@Id
@GeneratedValue
private Integer id;
private String name;
private String content;
}
@Entity
public class B extends Auditable<String> {
@Id
@GeneratedValue
private Integer id;
private String name;
private String content;
}
Persistence config class (for Spring Boot):
@Configuration
@EnableJpaAuditing
public class PersistenceConfig {
}
Everything works perfectly!
Thanks for your reply.. But for me A entity is not populating with the audit fields..I have updated other classes also.. could you pls verify it
– Saravanan
Nov 20 at 4:52
I have published my source code here. Hope it might be useful for you.
– huytmb
Nov 20 at 7:35
when i looked at my code B entity declared as abstract here... I have modified my code above. Could you please have a look at that huymb..?
– Saravanan
Nov 21 at 9:44
add a comment |
up vote
0
down vote
I added @Entity annotation to your classes:
@Entity
public class A extends B {
@Id
@GeneratedValue
private Integer id;
private String name;
private String content;
}
@Entity
public class B extends Auditable<String> {
@Id
@GeneratedValue
private Integer id;
private String name;
private String content;
}
Persistence config class (for Spring Boot):
@Configuration
@EnableJpaAuditing
public class PersistenceConfig {
}
Everything works perfectly!
Thanks for your reply.. But for me A entity is not populating with the audit fields..I have updated other classes also.. could you pls verify it
– Saravanan
Nov 20 at 4:52
I have published my source code here. Hope it might be useful for you.
– huytmb
Nov 20 at 7:35
when i looked at my code B entity declared as abstract here... I have modified my code above. Could you please have a look at that huymb..?
– Saravanan
Nov 21 at 9:44
add a comment |
up vote
0
down vote
up vote
0
down vote
I added @Entity annotation to your classes:
@Entity
public class A extends B {
@Id
@GeneratedValue
private Integer id;
private String name;
private String content;
}
@Entity
public class B extends Auditable<String> {
@Id
@GeneratedValue
private Integer id;
private String name;
private String content;
}
Persistence config class (for Spring Boot):
@Configuration
@EnableJpaAuditing
public class PersistenceConfig {
}
Everything works perfectly!
I added @Entity annotation to your classes:
@Entity
public class A extends B {
@Id
@GeneratedValue
private Integer id;
private String name;
private String content;
}
@Entity
public class B extends Auditable<String> {
@Id
@GeneratedValue
private Integer id;
private String name;
private String content;
}
Persistence config class (for Spring Boot):
@Configuration
@EnableJpaAuditing
public class PersistenceConfig {
}
Everything works perfectly!
edited Nov 20 at 7:17
answered Nov 19 at 15:26
huytmb
824
824
Thanks for your reply.. But for me A entity is not populating with the audit fields..I have updated other classes also.. could you pls verify it
– Saravanan
Nov 20 at 4:52
I have published my source code here. Hope it might be useful for you.
– huytmb
Nov 20 at 7:35
when i looked at my code B entity declared as abstract here... I have modified my code above. Could you please have a look at that huymb..?
– Saravanan
Nov 21 at 9:44
add a comment |
Thanks for your reply.. But for me A entity is not populating with the audit fields..I have updated other classes also.. could you pls verify it
– Saravanan
Nov 20 at 4:52
I have published my source code here. Hope it might be useful for you.
– huytmb
Nov 20 at 7:35
when i looked at my code B entity declared as abstract here... I have modified my code above. Could you please have a look at that huymb..?
– Saravanan
Nov 21 at 9:44
Thanks for your reply.. But for me A entity is not populating with the audit fields..I have updated other classes also.. could you pls verify it
– Saravanan
Nov 20 at 4:52
Thanks for your reply.. But for me A entity is not populating with the audit fields..I have updated other classes also.. could you pls verify it
– Saravanan
Nov 20 at 4:52
I have published my source code here. Hope it might be useful for you.
– huytmb
Nov 20 at 7:35
I have published my source code here. Hope it might be useful for you.
– huytmb
Nov 20 at 7:35
when i looked at my code B entity declared as abstract here... I have modified my code above. Could you please have a look at that huymb..?
– Saravanan
Nov 21 at 9:44
when i looked at my code B entity declared as abstract here... I have modified my code above. Could you please have a look at that huymb..?
– Saravanan
Nov 21 at 9:44
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53375607%2fauditingentitylistener-is-not-working-for-the-entity-that-extends-another-abstra%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Is class A defined as entity?
– Periklis Douvitsas
Nov 19 at 15:10
yes, i edited the code also
– Saravanan
Nov 20 at 4:42