-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Not work on createNativeQuery
PostPosted: Wed Oct 14, 2009 3:12 pm 
Newbie

Joined: Tue Jan 24, 2006 12:11 pm
Posts: 7
I try to call createNativeQuery:

List<Identity> results = entityManager.createNativeQuery("SELECT * FROM ANDRO_IDENTITY as i where " +
" i.IDENTITY_ID NOT IN (select tk.IDENTITY_ID from ANDRO_IDENTITY_TOKEN as tk where tk.TOKEN_ID = :token_id )",Identity.class)
.setFirstResult(0)
.setParameter("token_id", tokenId)
.getResultList();

and report error: The column name TOKEN_ID is not valid.

But when I directly query in the database like:

SELECT * FROM ANDRO_IDENTITY as i where i.IDENTITY_ID NOT IN (select tk.IDENTITY_ID from ANDRO_IDENTITY_TOKEN as tk where tk.TOKEN_ID = 2)


it works well.

May I know what I miss?


Thanks


Top
 Profile  
 
 Post subject: Re: Not work on createNativeQuery
PostPosted: Wed Oct 14, 2009 4:52 pm 
Senior
Senior

Joined: Mon Jul 07, 2008 4:35 pm
Posts: 141
Location: Berlin
Hi quintenjiang,

it would be helpful if you'd
  • provide the mappings for your entities involved with that query
  • use BBCode (see the buttons below the subject line). Makes your code much easier to read.

CU
Froestel

_________________
Have you tried turning it off and on again? [Roy]


Top
 Profile  
 
 Post subject: Re: Not work on createNativeQuery
PostPosted: Thu Oct 15, 2009 10:15 am 
Newbie

Joined: Tue Jan 24, 2006 12:11 pm
Posts: 7
Hi,

Identity class like:

@Entity
public class Identity {
private long ID;
private String identifier;
private String displayName;
private Token token;

}

andro_identity table design:
{
IDENTITY_ID long,
IDENTIFIER varchar,
DISPLAY_NAME varchar

}

and put token_id and joining table andro_identity_token
{
identity_id long
token_id
}

if I use native query createNativeQuery("SELECT * FROM ANDRO_IDENTITY i ", Identity.class), and try to be mapping to Identity, and exception, is lost token_id.

Question is how to design @SqlResultSetMapping(name="resultIdentity", entities=@EntityResult(entityClass=Identity.class) )

So I can query createNativeQuery("SELECT * FROM ANDRO_IDENTITY i ", "resultIdentity").


Thanks


Top
 Profile  
 
 Post subject: Re: Not work on createNativeQuery
PostPosted: Sat Oct 17, 2009 9:55 am 
Senior
Senior

Joined: Mon Jul 07, 2008 4:35 pm
Posts: 141
Location: Berlin
Hi quintenjiang,

this is very confusing what you write here and I'm not sure if I get this straight. Looks like TOKEN_ID is not valid because you have token_id as the name for the table field. Database, table, and field names are (usually) case sensitive.

CU
Froestel

_________________
Have you tried turning it off and on again? [Roy]


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.