-->
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.  [ 1 post ] 
Author Message
 Post subject: Native query with child object
PostPosted: Tue Apr 14, 2009 7:26 am 
Newbie

Joined: Mon Feb 12, 2007 6:57 am
Posts: 9
Hi all,

I'm experiencing a strange issue with a native query and was wondering whether anybody could help. What I have is the following code to get a random Tar object:

Code:
Query query = entityManager.createNativeQuery("SELECT * FROM IW.IW_FUND_TAR WHERE ROWNUM = 1", Tar.class);


The Tar class is defined as:

Code:
@Entity
@Table(name = "IW_FUND_TAR")
public class Tar {

...

   @OneToOne(fetch=FetchType.EAGER)
   @JoinColumn(name="locale", referencedColumnName="locale")
   private Locale locale;

...

}


And Locale is simply

Code:
@Entity
@Table(name = "TAR_LOCALE")
public class Locale {

   @Id
   private Long id;

   @Column
   private String locale;

}


The IW_FUND_TAR table has a string column called locale that is equal to the locale column on the TAR_LOCALE table. The problem when I try to execute the native query I get a ClassCaseException: Locale. I think Hibernate sees the Locale string in the query and then gets confused as it's expecting an object. Any ideas how to get round this?

Thanks

Nick


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

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.