-->
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: createNativeQuery and SqlResultSetMapping related question
PostPosted: Mon Jan 19, 2009 12:58 pm 
Newbie

Joined: Thu Dec 18, 2008 1:40 pm
Posts: 8
Hello All,

Learning to use Hibernate, JPA stuff. Trying to use createNativeQuery to which is getting common column values from 2 database tables by using Oracle's UNION function. Eventually need to get the field values from the query output assigned to corresponding variables of the code. I could have created a view from similar query used here and create the entity class using Hibernate Code Generator. That would have been lot easier for me to do. But just wanted to find out how I can do the same using createNativeQuery.

Any help or hints would be greatly appreciated.

Here's snippets of the codes I have along with the error message being generated -

Code:
public class table1 extends java.io.Serializable {

import javax.persistence.Query;
import javax.persistence.SqlResultSetMapping;
import javax.persistence.EntityResult;
import javax.persistence.FieldResult;

...

@Entity
@Table(name = "TABLE1", uniqueConstraints = {})
@SqlResultSetMapping(name="testing", entities =
        @EntityResult(entityClass=table1.class, fields= {
            @FieldResult(name="col1", column="col1"),
            @FieldResult(name="col2", column="col2"),
            @FieldResult(name="col3", column="col3"),
        })
)

...

public class TestAction  implements TestInterface {

public String col1;
...

@DataModel
private List<table1> queryresults;
...

// Here's sql statement for a Oracle 9i database
String sqlStmt = " select col1, col2, col3, col4  from (select col1, col2, col3, col4" +   
             "from table1" +   
             "union " +   
             "select col1, col2, col3, col4" +   
             "from table2) " +   
             "where col1 = :col1"; 
queryresults = em.createNativeQuery(sqlStmt, "testing").getResultList();   

// Not sure this would be the riqht way to get individual field value from
// the query result output list.
col1 = queryresults.get(0).getCol1();

...


But getting org.hibernate.QueryException: Not all named parameters have been set: ... error


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.