JPA @PostPersist How to access HttpServletRequest?JPA EntityManager: Why use persist() over merge()?Create the perfect JPA entityHibernate error persists an entity in @PostPersist methodWhat's the difference between JPA and Hibernate?What is difference between CrudRepository and JpaRepository interfaces in Spring Data JPA?Could not autowire Spring data JPA repositoryCustom ItemReader with spring-data-jpaJPA is creating columns by itselfSpring Data JPA Specification Manyto One realtionshipAdvanced JPA with pivot table
Can I call myself an assistant professor without a PhD?
How do I explain to a team that the project they will work on for six months will certainly be cancelled?
Blocking people from taking pictures of me with smartphone
Plausibility of Ice Eaters in the Arctic
How would I as a DM create a smart phone-like spell/device my players could use?
As a 16 year old, how can I keep my money safe from my mother?
Who are these characters/superheroes in the posters from Chris's room in Family Guy?
Why do oscilloscopes use SMPS instead of linear power supply?
Why does Intel's Haswell chip allow multiplication to be twice as fast as addition?
Simple book on model theory
Write an interpreter for *
Double blind peer review when paper cites author's GitHub repo for code
Are there any differences in causality between linear and logistic regression?
How many different ways are there to checkmate in the early game?
Is refreshing multiple times a test case for web applications?
How do we avoid CI-driven development...?
Can a College of Swords bard use Blade Flourishes multiple times in a turn?
What is the safest way to hook up car battery jump cables and why?
Are there any financial disadvantages to living significantly "below your means"?
Why did the RAAF procure the F/A-18 despite being purpose-built for carriers?
How does The Fools Guild make its money?
sed delete all the words before a match
What is my malfunctioning AI harvesting from humans?
What does Apple mean by "This may decrease battery life"?
JPA @PostPersist How to access HttpServletRequest?
JPA EntityManager: Why use persist() over merge()?Create the perfect JPA entityHibernate error persists an entity in @PostPersist methodWhat's the difference between JPA and Hibernate?What is difference between CrudRepository and JpaRepository interfaces in Spring Data JPA?Could not autowire Spring data JPA repositoryCustom ItemReader with spring-data-jpaJPA is creating columns by itselfSpring Data JPA Specification Manyto One realtionshipAdvanced JPA with pivot table
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have to implement @EntityListener
@Entity
@Table(name = "profile")
@Data
@EntityListeners(ProfileListener.class)
public class Profile implements Serializable
...
and ProfileListener.class I want to access HttpServletRequest for get some data to use inside @PostPersist
@PostPersist
public void PostPersist(Object ob) throws IOException
Edit
I tried to use
1.) RequestContextHolder
@PostPersist
public void PostPersist(Object ob) throws IOException
HttpServletRequest httpServletRequest = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
and I got error java.lang.NullPointerException
2.) ApplicationContext
@PostPersist
public void PostPersist(Object ob) throws IOException
HttpServletRequest httpServletRequest = ApplicationContextProvider.getApplicationContext().getBean(HttpServletRequest .class);
and I got error java.lang.NullPointerException
3.) @Autowired private HttpServletRequest request;
AFAIK ProfileListener.class is a class outside of Spring Application Context so I can't use Autowired
spring-boot jpa spring-data-jpa
|
show 5 more comments
I have to implement @EntityListener
@Entity
@Table(name = "profile")
@Data
@EntityListeners(ProfileListener.class)
public class Profile implements Serializable
...
and ProfileListener.class I want to access HttpServletRequest for get some data to use inside @PostPersist
@PostPersist
public void PostPersist(Object ob) throws IOException
Edit
I tried to use
1.) RequestContextHolder
@PostPersist
public void PostPersist(Object ob) throws IOException
HttpServletRequest httpServletRequest = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
and I got error java.lang.NullPointerException
2.) ApplicationContext
@PostPersist
public void PostPersist(Object ob) throws IOException
HttpServletRequest httpServletRequest = ApplicationContextProvider.getApplicationContext().getBean(HttpServletRequest .class);
and I got error java.lang.NullPointerException
3.) @Autowired private HttpServletRequest request;
AFAIK ProfileListener.class is a class outside of Spring Application Context so I can't use Autowired
spring-boot jpa spring-data-jpa
2
Don't... You really don't want to do that. Don't tie your entities to http.
– M. Deinum
Mar 27 at 7:40
Try autowiring@Autowired private HttpServletRequest request;
– Sudhir Ojha
Mar 27 at 7:42
Try to use RequestContextHolder class in Spring API. You can use it likeHttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder .currentRequestAttributes()).getRequest();
– Soner Okur
Mar 27 at 7:43
@Sudhir Ojha => Autowired doesn't work (request = null) . AFAIK ProfileListener.class is a class outside of Spring Application Context so I can't use Autowired and I tried to use ApplicationContent to get bean but it doesn't work also
– Panupong Kongarn
Mar 27 at 8:01
1
Which indicates you aren't running inside a http request or aren't using Spring but something like Jersey and the request context filter. or listener hasn't been setup.
– M. Deinum
Mar 27 at 9:46
|
show 5 more comments
I have to implement @EntityListener
@Entity
@Table(name = "profile")
@Data
@EntityListeners(ProfileListener.class)
public class Profile implements Serializable
...
and ProfileListener.class I want to access HttpServletRequest for get some data to use inside @PostPersist
@PostPersist
public void PostPersist(Object ob) throws IOException
Edit
I tried to use
1.) RequestContextHolder
@PostPersist
public void PostPersist(Object ob) throws IOException
HttpServletRequest httpServletRequest = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
and I got error java.lang.NullPointerException
2.) ApplicationContext
@PostPersist
public void PostPersist(Object ob) throws IOException
HttpServletRequest httpServletRequest = ApplicationContextProvider.getApplicationContext().getBean(HttpServletRequest .class);
and I got error java.lang.NullPointerException
3.) @Autowired private HttpServletRequest request;
AFAIK ProfileListener.class is a class outside of Spring Application Context so I can't use Autowired
spring-boot jpa spring-data-jpa
I have to implement @EntityListener
@Entity
@Table(name = "profile")
@Data
@EntityListeners(ProfileListener.class)
public class Profile implements Serializable
...
and ProfileListener.class I want to access HttpServletRequest for get some data to use inside @PostPersist
@PostPersist
public void PostPersist(Object ob) throws IOException
Edit
I tried to use
1.) RequestContextHolder
@PostPersist
public void PostPersist(Object ob) throws IOException
HttpServletRequest httpServletRequest = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
and I got error java.lang.NullPointerException
2.) ApplicationContext
@PostPersist
public void PostPersist(Object ob) throws IOException
HttpServletRequest httpServletRequest = ApplicationContextProvider.getApplicationContext().getBean(HttpServletRequest .class);
and I got error java.lang.NullPointerException
3.) @Autowired private HttpServletRequest request;
AFAIK ProfileListener.class is a class outside of Spring Application Context so I can't use Autowired
spring-boot jpa spring-data-jpa
spring-boot jpa spring-data-jpa
edited Mar 27 at 9:20
Panupong Kongarn
asked Mar 27 at 7:37
Panupong KongarnPanupong Kongarn
1,1521 gold badge11 silver badges32 bronze badges
1,1521 gold badge11 silver badges32 bronze badges
2
Don't... You really don't want to do that. Don't tie your entities to http.
– M. Deinum
Mar 27 at 7:40
Try autowiring@Autowired private HttpServletRequest request;
– Sudhir Ojha
Mar 27 at 7:42
Try to use RequestContextHolder class in Spring API. You can use it likeHttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder .currentRequestAttributes()).getRequest();
– Soner Okur
Mar 27 at 7:43
@Sudhir Ojha => Autowired doesn't work (request = null) . AFAIK ProfileListener.class is a class outside of Spring Application Context so I can't use Autowired and I tried to use ApplicationContent to get bean but it doesn't work also
– Panupong Kongarn
Mar 27 at 8:01
1
Which indicates you aren't running inside a http request or aren't using Spring but something like Jersey and the request context filter. or listener hasn't been setup.
– M. Deinum
Mar 27 at 9:46
|
show 5 more comments
2
Don't... You really don't want to do that. Don't tie your entities to http.
– M. Deinum
Mar 27 at 7:40
Try autowiring@Autowired private HttpServletRequest request;
– Sudhir Ojha
Mar 27 at 7:42
Try to use RequestContextHolder class in Spring API. You can use it likeHttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder .currentRequestAttributes()).getRequest();
– Soner Okur
Mar 27 at 7:43
@Sudhir Ojha => Autowired doesn't work (request = null) . AFAIK ProfileListener.class is a class outside of Spring Application Context so I can't use Autowired and I tried to use ApplicationContent to get bean but it doesn't work also
– Panupong Kongarn
Mar 27 at 8:01
1
Which indicates you aren't running inside a http request or aren't using Spring but something like Jersey and the request context filter. or listener hasn't been setup.
– M. Deinum
Mar 27 at 9:46
2
2
Don't... You really don't want to do that. Don't tie your entities to http.
– M. Deinum
Mar 27 at 7:40
Don't... You really don't want to do that. Don't tie your entities to http.
– M. Deinum
Mar 27 at 7:40
Try autowiring
@Autowired private HttpServletRequest request;– Sudhir Ojha
Mar 27 at 7:42
Try autowiring
@Autowired private HttpServletRequest request;– Sudhir Ojha
Mar 27 at 7:42
Try to use RequestContextHolder class in Spring API. You can use it like
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder .currentRequestAttributes()).getRequest();– Soner Okur
Mar 27 at 7:43
Try to use RequestContextHolder class in Spring API. You can use it like
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder .currentRequestAttributes()).getRequest();– Soner Okur
Mar 27 at 7:43
@Sudhir Ojha => Autowired doesn't work (request = null) . AFAIK ProfileListener.class is a class outside of Spring Application Context so I can't use Autowired and I tried to use ApplicationContent to get bean but it doesn't work also
– Panupong Kongarn
Mar 27 at 8:01
@Sudhir Ojha => Autowired doesn't work (request = null) . AFAIK ProfileListener.class is a class outside of Spring Application Context so I can't use Autowired and I tried to use ApplicationContent to get bean but it doesn't work also
– Panupong Kongarn
Mar 27 at 8:01
1
1
Which indicates you aren't running inside a http request or aren't using Spring but something like Jersey and the request context filter. or listener hasn't been setup.
– M. Deinum
Mar 27 at 9:46
Which indicates you aren't running inside a http request or aren't using Spring but something like Jersey and the request context filter. or listener hasn't been setup.
– M. Deinum
Mar 27 at 9:46
|
show 5 more comments
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
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%2f55371998%2fjpa-postpersist-how-to-access-httpservletrequest%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.
Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.
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.
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%2f55371998%2fjpa-postpersist-how-to-access-httpservletrequest%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
2
Don't... You really don't want to do that. Don't tie your entities to http.
– M. Deinum
Mar 27 at 7:40
Try autowiring
@Autowired private HttpServletRequest request;– Sudhir Ojha
Mar 27 at 7:42
Try to use RequestContextHolder class in Spring API. You can use it like
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder .currentRequestAttributes()).getRequest();– Soner Okur
Mar 27 at 7:43
@Sudhir Ojha => Autowired doesn't work (request = null) . AFAIK ProfileListener.class is a class outside of Spring Application Context so I can't use Autowired and I tried to use ApplicationContent to get bean but it doesn't work also
– Panupong Kongarn
Mar 27 at 8:01
1
Which indicates you aren't running inside a http request or aren't using Spring but something like Jersey and the request context filter. or listener hasn't been setup.
– M. Deinum
Mar 27 at 9:46