Suppress error message No entity found for query
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I use this code to get single row result:
@Override
public PaymentTransactions transactionByUnique_Id(String unique_id) throws Exception {
String hql = "select e from " + PaymentTransactions.class.getName() + " e where e.unique_id = :unique_id";
Query query = entityManager.createQuery(hql).setParameter("unique_id", unique_id);
PaymentTransactions paymentTransaction = (PaymentTransactions) query.getSingleResult();
return paymentTransaction;
}
But when I don't have matching row I get exception:
14:25:41,736 INFO [stdout] (default task-1) javax.persistence.NoResultException: No entity found for query
How I can suppress that exception and just to continue code execution?
java jpa spring-data
add a comment |
I use this code to get single row result:
@Override
public PaymentTransactions transactionByUnique_Id(String unique_id) throws Exception {
String hql = "select e from " + PaymentTransactions.class.getName() + " e where e.unique_id = :unique_id";
Query query = entityManager.createQuery(hql).setParameter("unique_id", unique_id);
PaymentTransactions paymentTransaction = (PaymentTransactions) query.getSingleResult();
return paymentTransaction;
}
But when I don't have matching row I get exception:
14:25:41,736 INFO [stdout] (default task-1) javax.persistence.NoResultException: No entity found for query
How I can suppress that exception and just to continue code execution?
java jpa spring-data
Call getResultList(), and return its first element if it's present. Also, please, respect the Java naming conventions, and use a TypedQuery.
– JB Nizet
Nov 24 '18 at 12:31
How should I change the code in order to use TypedQuery?
– Peter Penzov
Nov 24 '18 at 12:36
1
docs.oracle.com/javaee/7/api/javax/persistence/…
– JB Nizet
Nov 24 '18 at 12:38
Basic java is catching an exception and returning a different result from your method based on that. Nothing to do with the JPA API
– user3973283
Nov 24 '18 at 17:29
add a comment |
I use this code to get single row result:
@Override
public PaymentTransactions transactionByUnique_Id(String unique_id) throws Exception {
String hql = "select e from " + PaymentTransactions.class.getName() + " e where e.unique_id = :unique_id";
Query query = entityManager.createQuery(hql).setParameter("unique_id", unique_id);
PaymentTransactions paymentTransaction = (PaymentTransactions) query.getSingleResult();
return paymentTransaction;
}
But when I don't have matching row I get exception:
14:25:41,736 INFO [stdout] (default task-1) javax.persistence.NoResultException: No entity found for query
How I can suppress that exception and just to continue code execution?
java jpa spring-data
I use this code to get single row result:
@Override
public PaymentTransactions transactionByUnique_Id(String unique_id) throws Exception {
String hql = "select e from " + PaymentTransactions.class.getName() + " e where e.unique_id = :unique_id";
Query query = entityManager.createQuery(hql).setParameter("unique_id", unique_id);
PaymentTransactions paymentTransaction = (PaymentTransactions) query.getSingleResult();
return paymentTransaction;
}
But when I don't have matching row I get exception:
14:25:41,736 INFO [stdout] (default task-1) javax.persistence.NoResultException: No entity found for query
How I can suppress that exception and just to continue code execution?
java jpa spring-data
java jpa spring-data
asked Nov 24 '18 at 12:29
Peter PenzovPeter Penzov
27461191399
27461191399
Call getResultList(), and return its first element if it's present. Also, please, respect the Java naming conventions, and use a TypedQuery.
– JB Nizet
Nov 24 '18 at 12:31
How should I change the code in order to use TypedQuery?
– Peter Penzov
Nov 24 '18 at 12:36
1
docs.oracle.com/javaee/7/api/javax/persistence/…
– JB Nizet
Nov 24 '18 at 12:38
Basic java is catching an exception and returning a different result from your method based on that. Nothing to do with the JPA API
– user3973283
Nov 24 '18 at 17:29
add a comment |
Call getResultList(), and return its first element if it's present. Also, please, respect the Java naming conventions, and use a TypedQuery.
– JB Nizet
Nov 24 '18 at 12:31
How should I change the code in order to use TypedQuery?
– Peter Penzov
Nov 24 '18 at 12:36
1
docs.oracle.com/javaee/7/api/javax/persistence/…
– JB Nizet
Nov 24 '18 at 12:38
Basic java is catching an exception and returning a different result from your method based on that. Nothing to do with the JPA API
– user3973283
Nov 24 '18 at 17:29
Call getResultList(), and return its first element if it's present. Also, please, respect the Java naming conventions, and use a TypedQuery.
– JB Nizet
Nov 24 '18 at 12:31
Call getResultList(), and return its first element if it's present. Also, please, respect the Java naming conventions, and use a TypedQuery.
– JB Nizet
Nov 24 '18 at 12:31
How should I change the code in order to use TypedQuery?
– Peter Penzov
Nov 24 '18 at 12:36
How should I change the code in order to use TypedQuery?
– Peter Penzov
Nov 24 '18 at 12:36
1
1
docs.oracle.com/javaee/7/api/javax/persistence/…
– JB Nizet
Nov 24 '18 at 12:38
docs.oracle.com/javaee/7/api/javax/persistence/…
– JB Nizet
Nov 24 '18 at 12:38
Basic java is catching an exception and returning a different result from your method based on that. Nothing to do with the JPA API
– user3973283
Nov 24 '18 at 17:29
Basic java is catching an exception and returning a different result from your method based on that. Nothing to do with the JPA API
– user3973283
Nov 24 '18 at 17:29
add a comment |
2 Answers
2
active
oldest
votes
Just throw and catch javax.persistence.NoResultException exception and continue your code execution.
Possible duplicate of How to continue program execution even after throwing exception?
add a comment |
Just update way to logging:
log4j.logger.javax.persistence=WARN
ok, but I don't want to get Java exception.
– Peter Penzov
Nov 24 '18 at 14:53
I updated it, could you try it?
– Jonathan Johx
Nov 24 '18 at 15:16
add a comment |
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%2f53458151%2fsuppress-error-message-no-entity-found-for-query%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Just throw and catch javax.persistence.NoResultException exception and continue your code execution.
Possible duplicate of How to continue program execution even after throwing exception?
add a comment |
Just throw and catch javax.persistence.NoResultException exception and continue your code execution.
Possible duplicate of How to continue program execution even after throwing exception?
add a comment |
Just throw and catch javax.persistence.NoResultException exception and continue your code execution.
Possible duplicate of How to continue program execution even after throwing exception?
Just throw and catch javax.persistence.NoResultException exception and continue your code execution.
Possible duplicate of How to continue program execution even after throwing exception?
answered Nov 24 '18 at 16:47
Ravi SharmaRavi Sharma
1814
1814
add a comment |
add a comment |
Just update way to logging:
log4j.logger.javax.persistence=WARN
ok, but I don't want to get Java exception.
– Peter Penzov
Nov 24 '18 at 14:53
I updated it, could you try it?
– Jonathan Johx
Nov 24 '18 at 15:16
add a comment |
Just update way to logging:
log4j.logger.javax.persistence=WARN
ok, but I don't want to get Java exception.
– Peter Penzov
Nov 24 '18 at 14:53
I updated it, could you try it?
– Jonathan Johx
Nov 24 '18 at 15:16
add a comment |
Just update way to logging:
log4j.logger.javax.persistence=WARN
Just update way to logging:
log4j.logger.javax.persistence=WARN
edited Nov 24 '18 at 15:15
answered Nov 24 '18 at 13:57
Jonathan JohxJonathan Johx
1
1
ok, but I don't want to get Java exception.
– Peter Penzov
Nov 24 '18 at 14:53
I updated it, could you try it?
– Jonathan Johx
Nov 24 '18 at 15:16
add a comment |
ok, but I don't want to get Java exception.
– Peter Penzov
Nov 24 '18 at 14:53
I updated it, could you try it?
– Jonathan Johx
Nov 24 '18 at 15:16
ok, but I don't want to get Java exception.
– Peter Penzov
Nov 24 '18 at 14:53
ok, but I don't want to get Java exception.
– Peter Penzov
Nov 24 '18 at 14:53
I updated it, could you try it?
– Jonathan Johx
Nov 24 '18 at 15:16
I updated it, could you try it?
– Jonathan Johx
Nov 24 '18 at 15:16
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.
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%2f53458151%2fsuppress-error-message-no-entity-found-for-query%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
Call getResultList(), and return its first element if it's present. Also, please, respect the Java naming conventions, and use a TypedQuery.
– JB Nizet
Nov 24 '18 at 12:31
How should I change the code in order to use TypedQuery?
– Peter Penzov
Nov 24 '18 at 12:36
1
docs.oracle.com/javaee/7/api/javax/persistence/…
– JB Nizet
Nov 24 '18 at 12:38
Basic java is catching an exception and returning a different result from your method based on that. Nothing to do with the JPA API
– user3973283
Nov 24 '18 at 17:29