hibernate query giving an inccorect result list
this is the method Dao layer List,
public List<PortfolioMemberView> getPortfolioMemberViewByPid(Integer pid){
//check the portfolioId value in console
System.out.print(pid);
try {
Session session = sessionFactory.getCurrentSession();
String sql = "from PortfolioMemberView pv where pv.portfolioId = ?0";
Query query = session.createQuery(sql).setParameter(0, pid);
List<PortfolioMemberView> pmvl = query.list();
//check the result list by assetCode in console
for(PortfolioMemberView pv: pmvl){
System.out.print(pv.getAssetCode());
}
return pmvl;
}catch(Exception e){
logger.info("操作失败:" + e.getMessage() + ", " +e.getCause());
throw new RuntimeException();
}
I have a view(That I create) PortfolioMemberView in my database
and it has the following data
inmage
when I involke the method, the console print following result.
2
Hibernate: select portfoliom0_.portfolioId as portfoli1_8_,
portfoliom0_.assetId as assetId2_8_, portfoliom0_.accountType as accountT3_8_, portfoliom0_.assetCode as assetCod4_8_, portfoliom0_.assetLabel as assetLab5_8_, portfoliom0_.value_ as value_6_8_, portfoliom0_.annualReturn as annualRe7_8_, portfoliom0_.returnRate as returnRa8_8_ from PortfolioMemberView portfoliom0_ where portfoliom0_.portfolioId=?
CMPROP0121CMPROP0121CMPROP0121CMPROP0121CMPROP0121
The expected result should be CMPROP0121kckbGYck, because when portfolioId = 2, the assetCode of three object in the resulting list shoud be CMPROP0121,kckb,GYck.
I also copy the query hibenate generated and run it at mysql database, and the result is correct.
Hibernate: select portfoliom0_.portfolioId as portfoli1_8_,
portfoliom0_.assetId as assetId2_8_, portfoliom0_.accountType as accountT3_8_, portfoliom0_.assetCode as assetCod4_8_, portfoliom0_.assetLabel as assetLab5_8_, portfoliom0_.value_ as value_6_8_, portfoliom0_.annualReturn as annualRe7_8_, portfoliom0_.returnRate as returnRa8_8_ from PortfolioMemberView portfoliom0_ where portfoliom0_.portfolioId=?
not sure what's wrong, pls help!!!
java mysql database hibernate hql
|
show 6 more comments
this is the method Dao layer List,
public List<PortfolioMemberView> getPortfolioMemberViewByPid(Integer pid){
//check the portfolioId value in console
System.out.print(pid);
try {
Session session = sessionFactory.getCurrentSession();
String sql = "from PortfolioMemberView pv where pv.portfolioId = ?0";
Query query = session.createQuery(sql).setParameter(0, pid);
List<PortfolioMemberView> pmvl = query.list();
//check the result list by assetCode in console
for(PortfolioMemberView pv: pmvl){
System.out.print(pv.getAssetCode());
}
return pmvl;
}catch(Exception e){
logger.info("操作失败:" + e.getMessage() + ", " +e.getCause());
throw new RuntimeException();
}
I have a view(That I create) PortfolioMemberView in my database
and it has the following data
inmage
when I involke the method, the console print following result.
2
Hibernate: select portfoliom0_.portfolioId as portfoli1_8_,
portfoliom0_.assetId as assetId2_8_, portfoliom0_.accountType as accountT3_8_, portfoliom0_.assetCode as assetCod4_8_, portfoliom0_.assetLabel as assetLab5_8_, portfoliom0_.value_ as value_6_8_, portfoliom0_.annualReturn as annualRe7_8_, portfoliom0_.returnRate as returnRa8_8_ from PortfolioMemberView portfoliom0_ where portfoliom0_.portfolioId=?
CMPROP0121CMPROP0121CMPROP0121CMPROP0121CMPROP0121
The expected result should be CMPROP0121kckbGYck, because when portfolioId = 2, the assetCode of three object in the resulting list shoud be CMPROP0121,kckb,GYck.
I also copy the query hibenate generated and run it at mysql database, and the result is correct.
Hibernate: select portfoliom0_.portfolioId as portfoli1_8_,
portfoliom0_.assetId as assetId2_8_, portfoliom0_.accountType as accountT3_8_, portfoliom0_.assetCode as assetCod4_8_, portfoliom0_.assetLabel as assetLab5_8_, portfoliom0_.value_ as value_6_8_, portfoliom0_.annualReturn as annualRe7_8_, portfoliom0_.returnRate as returnRa8_8_ from PortfolioMemberView portfoliom0_ where portfoliom0_.portfolioId=?
not sure what's wrong, pls help!!!
java mysql database hibernate hql
String sql = "from PortfolioMemberView pv where pv.portfolioId = ?"; Try removing the ?0 on the query. Just use ?
– eddySoft
Nov 25 '18 at 11:21
it gives me an Exception, legacy way... :org.hibernate.QueryException: Legacy-style query parameters (?) are no longer supported; use JPA-style ordinal parameters (e.g.,?1) instead : from pojoView.PortfolioMemberView pv where pv.portfolioId=? [from pojoView.PortfolioMemberView pv where pv.portfolioId=?], org.hibernate.QueryException: Legacy-style query parameters (?) are no longer supported; use JPA-style ordinal parameters (e.g.,?1) instead : from pojoView.PortfolioMemberView pv where pv.portfolioId=? [from pojoView.PortfolioMemberView pv where pv.portfolioId=?]
– user8886451
Nov 25 '18 at 11:27
PLease just so i undestand the issue, try this form of BindingString sql = "from PortfolioMemberView pv where pv.portfolioId = :pid"; Query query = session.createQuery(sql).setParameter("pid", pid);
– eddySoft
Nov 25 '18 at 11:32
i just tried,it print the same incorrect answer
– user8886451
Nov 25 '18 at 11:36
What are the results you are getting from the database?
– eddySoft
Nov 25 '18 at 11:43
|
show 6 more comments
this is the method Dao layer List,
public List<PortfolioMemberView> getPortfolioMemberViewByPid(Integer pid){
//check the portfolioId value in console
System.out.print(pid);
try {
Session session = sessionFactory.getCurrentSession();
String sql = "from PortfolioMemberView pv where pv.portfolioId = ?0";
Query query = session.createQuery(sql).setParameter(0, pid);
List<PortfolioMemberView> pmvl = query.list();
//check the result list by assetCode in console
for(PortfolioMemberView pv: pmvl){
System.out.print(pv.getAssetCode());
}
return pmvl;
}catch(Exception e){
logger.info("操作失败:" + e.getMessage() + ", " +e.getCause());
throw new RuntimeException();
}
I have a view(That I create) PortfolioMemberView in my database
and it has the following data
inmage
when I involke the method, the console print following result.
2
Hibernate: select portfoliom0_.portfolioId as portfoli1_8_,
portfoliom0_.assetId as assetId2_8_, portfoliom0_.accountType as accountT3_8_, portfoliom0_.assetCode as assetCod4_8_, portfoliom0_.assetLabel as assetLab5_8_, portfoliom0_.value_ as value_6_8_, portfoliom0_.annualReturn as annualRe7_8_, portfoliom0_.returnRate as returnRa8_8_ from PortfolioMemberView portfoliom0_ where portfoliom0_.portfolioId=?
CMPROP0121CMPROP0121CMPROP0121CMPROP0121CMPROP0121
The expected result should be CMPROP0121kckbGYck, because when portfolioId = 2, the assetCode of three object in the resulting list shoud be CMPROP0121,kckb,GYck.
I also copy the query hibenate generated and run it at mysql database, and the result is correct.
Hibernate: select portfoliom0_.portfolioId as portfoli1_8_,
portfoliom0_.assetId as assetId2_8_, portfoliom0_.accountType as accountT3_8_, portfoliom0_.assetCode as assetCod4_8_, portfoliom0_.assetLabel as assetLab5_8_, portfoliom0_.value_ as value_6_8_, portfoliom0_.annualReturn as annualRe7_8_, portfoliom0_.returnRate as returnRa8_8_ from PortfolioMemberView portfoliom0_ where portfoliom0_.portfolioId=?
not sure what's wrong, pls help!!!
java mysql database hibernate hql
this is the method Dao layer List,
public List<PortfolioMemberView> getPortfolioMemberViewByPid(Integer pid){
//check the portfolioId value in console
System.out.print(pid);
try {
Session session = sessionFactory.getCurrentSession();
String sql = "from PortfolioMemberView pv where pv.portfolioId = ?0";
Query query = session.createQuery(sql).setParameter(0, pid);
List<PortfolioMemberView> pmvl = query.list();
//check the result list by assetCode in console
for(PortfolioMemberView pv: pmvl){
System.out.print(pv.getAssetCode());
}
return pmvl;
}catch(Exception e){
logger.info("操作失败:" + e.getMessage() + ", " +e.getCause());
throw new RuntimeException();
}
I have a view(That I create) PortfolioMemberView in my database
and it has the following data
inmage
when I involke the method, the console print following result.
2
Hibernate: select portfoliom0_.portfolioId as portfoli1_8_,
portfoliom0_.assetId as assetId2_8_, portfoliom0_.accountType as accountT3_8_, portfoliom0_.assetCode as assetCod4_8_, portfoliom0_.assetLabel as assetLab5_8_, portfoliom0_.value_ as value_6_8_, portfoliom0_.annualReturn as annualRe7_8_, portfoliom0_.returnRate as returnRa8_8_ from PortfolioMemberView portfoliom0_ where portfoliom0_.portfolioId=?
CMPROP0121CMPROP0121CMPROP0121CMPROP0121CMPROP0121
The expected result should be CMPROP0121kckbGYck, because when portfolioId = 2, the assetCode of three object in the resulting list shoud be CMPROP0121,kckb,GYck.
I also copy the query hibenate generated and run it at mysql database, and the result is correct.
Hibernate: select portfoliom0_.portfolioId as portfoli1_8_,
portfoliom0_.assetId as assetId2_8_, portfoliom0_.accountType as accountT3_8_, portfoliom0_.assetCode as assetCod4_8_, portfoliom0_.assetLabel as assetLab5_8_, portfoliom0_.value_ as value_6_8_, portfoliom0_.annualReturn as annualRe7_8_, portfoliom0_.returnRate as returnRa8_8_ from PortfolioMemberView portfoliom0_ where portfoliom0_.portfolioId=?
not sure what's wrong, pls help!!!
java mysql database hibernate hql
java mysql database hibernate hql
asked Nov 25 '18 at 11:12
user8886451user8886451
1
1
String sql = "from PortfolioMemberView pv where pv.portfolioId = ?"; Try removing the ?0 on the query. Just use ?
– eddySoft
Nov 25 '18 at 11:21
it gives me an Exception, legacy way... :org.hibernate.QueryException: Legacy-style query parameters (?) are no longer supported; use JPA-style ordinal parameters (e.g.,?1) instead : from pojoView.PortfolioMemberView pv where pv.portfolioId=? [from pojoView.PortfolioMemberView pv where pv.portfolioId=?], org.hibernate.QueryException: Legacy-style query parameters (?) are no longer supported; use JPA-style ordinal parameters (e.g.,?1) instead : from pojoView.PortfolioMemberView pv where pv.portfolioId=? [from pojoView.PortfolioMemberView pv where pv.portfolioId=?]
– user8886451
Nov 25 '18 at 11:27
PLease just so i undestand the issue, try this form of BindingString sql = "from PortfolioMemberView pv where pv.portfolioId = :pid"; Query query = session.createQuery(sql).setParameter("pid", pid);
– eddySoft
Nov 25 '18 at 11:32
i just tried,it print the same incorrect answer
– user8886451
Nov 25 '18 at 11:36
What are the results you are getting from the database?
– eddySoft
Nov 25 '18 at 11:43
|
show 6 more comments
String sql = "from PortfolioMemberView pv where pv.portfolioId = ?"; Try removing the ?0 on the query. Just use ?
– eddySoft
Nov 25 '18 at 11:21
it gives me an Exception, legacy way... :org.hibernate.QueryException: Legacy-style query parameters (?) are no longer supported; use JPA-style ordinal parameters (e.g.,?1) instead : from pojoView.PortfolioMemberView pv where pv.portfolioId=? [from pojoView.PortfolioMemberView pv where pv.portfolioId=?], org.hibernate.QueryException: Legacy-style query parameters (?) are no longer supported; use JPA-style ordinal parameters (e.g.,?1) instead : from pojoView.PortfolioMemberView pv where pv.portfolioId=? [from pojoView.PortfolioMemberView pv where pv.portfolioId=?]
– user8886451
Nov 25 '18 at 11:27
PLease just so i undestand the issue, try this form of BindingString sql = "from PortfolioMemberView pv where pv.portfolioId = :pid"; Query query = session.createQuery(sql).setParameter("pid", pid);
– eddySoft
Nov 25 '18 at 11:32
i just tried,it print the same incorrect answer
– user8886451
Nov 25 '18 at 11:36
What are the results you are getting from the database?
– eddySoft
Nov 25 '18 at 11:43
String sql = "from PortfolioMemberView pv where pv.portfolioId = ?"; Try removing the ?0 on the query. Just use ?
– eddySoft
Nov 25 '18 at 11:21
String sql = "from PortfolioMemberView pv where pv.portfolioId = ?"; Try removing the ?0 on the query. Just use ?
– eddySoft
Nov 25 '18 at 11:21
it gives me an Exception, legacy way... :org.hibernate.QueryException: Legacy-style query parameters (
?) are no longer supported; use JPA-style ordinal parameters (e.g., ?1) instead : from pojoView.PortfolioMemberView pv where pv.portfolioId=? [from pojoView.PortfolioMemberView pv where pv.portfolioId=?], org.hibernate.QueryException: Legacy-style query parameters (?) are no longer supported; use JPA-style ordinal parameters (e.g., ?1) instead : from pojoView.PortfolioMemberView pv where pv.portfolioId=? [from pojoView.PortfolioMemberView pv where pv.portfolioId=?]– user8886451
Nov 25 '18 at 11:27
it gives me an Exception, legacy way... :org.hibernate.QueryException: Legacy-style query parameters (
?) are no longer supported; use JPA-style ordinal parameters (e.g., ?1) instead : from pojoView.PortfolioMemberView pv where pv.portfolioId=? [from pojoView.PortfolioMemberView pv where pv.portfolioId=?], org.hibernate.QueryException: Legacy-style query parameters (?) are no longer supported; use JPA-style ordinal parameters (e.g., ?1) instead : from pojoView.PortfolioMemberView pv where pv.portfolioId=? [from pojoView.PortfolioMemberView pv where pv.portfolioId=?]– user8886451
Nov 25 '18 at 11:27
PLease just so i undestand the issue, try this form of Binding
String sql = "from PortfolioMemberView pv where pv.portfolioId = :pid"; Query query = session.createQuery(sql).setParameter("pid", pid);– eddySoft
Nov 25 '18 at 11:32
PLease just so i undestand the issue, try this form of Binding
String sql = "from PortfolioMemberView pv where pv.portfolioId = :pid"; Query query = session.createQuery(sql).setParameter("pid", pid);– eddySoft
Nov 25 '18 at 11:32
i just tried,it print the same incorrect answer
– user8886451
Nov 25 '18 at 11:36
i just tried,it print the same incorrect answer
– user8886451
Nov 25 '18 at 11:36
What are the results you are getting from the database?
– eddySoft
Nov 25 '18 at 11:43
What are the results you are getting from the database?
– eddySoft
Nov 25 '18 at 11:43
|
show 6 more comments
1 Answer
1
active
oldest
votes
I mapped portfolioId as primary Id, and primary Id cannot be duplicated. but obviously the primary key portfolioId is duplicated. I make aother primary key portfolioMemberId, and the problem solved
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%2f53466879%2fhibernate-query-giving-an-inccorect-result-list%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I mapped portfolioId as primary Id, and primary Id cannot be duplicated. but obviously the primary key portfolioId is duplicated. I make aother primary key portfolioMemberId, and the problem solved
add a comment |
I mapped portfolioId as primary Id, and primary Id cannot be duplicated. but obviously the primary key portfolioId is duplicated. I make aother primary key portfolioMemberId, and the problem solved
add a comment |
I mapped portfolioId as primary Id, and primary Id cannot be duplicated. but obviously the primary key portfolioId is duplicated. I make aother primary key portfolioMemberId, and the problem solved
I mapped portfolioId as primary Id, and primary Id cannot be duplicated. but obviously the primary key portfolioId is duplicated. I make aother primary key portfolioMemberId, and the problem solved
answered Nov 26 '18 at 5:30
user8886451user8886451
1
1
add a comment |
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%2f53466879%2fhibernate-query-giving-an-inccorect-result-list%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
String sql = "from PortfolioMemberView pv where pv.portfolioId = ?"; Try removing the ?0 on the query. Just use ?
– eddySoft
Nov 25 '18 at 11:21
it gives me an Exception, legacy way... :org.hibernate.QueryException: Legacy-style query parameters (
?) are no longer supported; use JPA-style ordinal parameters (e.g.,?1) instead : from pojoView.PortfolioMemberView pv where pv.portfolioId=? [from pojoView.PortfolioMemberView pv where pv.portfolioId=?], org.hibernate.QueryException: Legacy-style query parameters (?) are no longer supported; use JPA-style ordinal parameters (e.g.,?1) instead : from pojoView.PortfolioMemberView pv where pv.portfolioId=? [from pojoView.PortfolioMemberView pv where pv.portfolioId=?]– user8886451
Nov 25 '18 at 11:27
PLease just so i undestand the issue, try this form of Binding
String sql = "from PortfolioMemberView pv where pv.portfolioId = :pid"; Query query = session.createQuery(sql).setParameter("pid", pid);– eddySoft
Nov 25 '18 at 11:32
i just tried,it print the same incorrect answer
– user8886451
Nov 25 '18 at 11:36
What are the results you are getting from the database?
– eddySoft
Nov 25 '18 at 11:43