-->
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.  [ 2 posts ] 
Author Message
 Post subject: [JPA, SqlResultSetMapping] strange bahaviour
PostPosted: Thu Dec 11, 2008 8:33 am 
Newbie

Joined: Sat Oct 28, 2006 3:05 pm
Posts: 10
Hi.
I have an entity which also defines a SqlResultSetMapping:
Code:
package model;

@Entity
@Table(name = "BIDDER")
@SqlResultSetMapping(name = "test",
        entities = @EntityResult(entityClass = Bidder.class))
public class Bidder {

    @Id
    @Column(name = "ID")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "BIDDER_GENERATOR")
    @SequenceGenerator(name = "BIDDER_GENERATOR", sequenceName = "BIDDER_SEQ", allocationSize = 1)
    private long id;

    @Column(name = "NAME")
    private String name;

    /* package */Bidder() {
        // default
    }

    public Bidder(String name) {
        this.name = name;
    }

    public long getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    @Override
    public String toString() {
        return "Bidder: " + name + ", id = " + id;
    }
}

Then, I execute a native SQL query:
Code:
Query q = em.createNativeQuery("select id from bidder where id = 999", "test");
Bidder bidder = (Bidder) q.getSingleResult();

and an exception is thrown, and the log output is:
Code:
INFO: 13:13:30,933 DEBUG SQL:111 - select * from ( select id from bidder where id = 999 ) where rownum <= ?

INFO: Hibernate: select * from ( select id from bidder where id = 999 ) where rownum <= ?
INFO: 13:13:30,956 TRACE LongType:193 - returning '999' as column: ID

INFO: 13:13:31,004  INFO StringType:203 - could not read column value from result set: NAME; Invalid column name

INFO: 13:13:31,019  WARN JDBCExceptionReporter:100 - SQL Error: 17006, SQLState: null

INFO: 13:13:31,025 ERROR JDBCExceptionReporter:101 - Invalid column name

When I change the SqlResultSetMapping to be:
Code:
@Entity
@Table(name = "BIDDER")
@SqlResultSetMapping(name = "test",
        entities = @EntityResult(
                entityClass = Bidder.class,
                fields = @FieldResult(name = "id", column = "ID")))

the only thing that changes is the alias for the NAME column:
Code:
INFO: 13:23:04,502 DEBUG SQL:111 - select * from ( select id from bidder where id = 999 ) where rownum <= ?

INFO: Hibernate: select * from ( select id from bidder where id = 999 ) where rownum <= ?
INFO: 13:23:04,730 TRACE LongType:193 - returning '999' as column: ID

INFO: 13:23:04,748  INFO StringType:203 - could not read column value from result set: NAME1_0_; Invalid column name

INFO: 13:23:04,754  WARN JDBCExceptionReporter:100 - SQL Error: 17006, SQLState: null

INFO: 13:23:04,754 ERROR JDBCExceptionReporter:101 - Invalid column name


In Enterprise JavaBeans by Bill Burke, example 9.3.3.1, they do a similar thing - they map an entity but specify only a few columns.

Looks like Hibernate is trying to extract all fields from the entity, even though the SQL retrieves only 1 field. And why is the "where rownum <= ?" used in the query? This doesn't seem to be relevant here.

What am I doing wrong?

DB: Oracle XE 10g
OS: Kubuntu 8.04, amd64
Hibernate core: 3.3.0.SP1 (bundled in entitymanager download)
Hibernate EntityManager: 3.4.0.GA
Application server: Glassfish v2


Top
 Profile  
 
 Post subject: Re: [JPA, SqlResultSetMapping] strange bahaviour
PostPosted: Thu May 07, 2009 2:20 am 
Newbie

Joined: Thu Nov 06, 2008 10:42 am
Posts: 5
Hi,

I reached page after searching for the same "Invalid column" Issue. Has anybody found a solution? Please respond.
Given my limited knowledge, it looks like a bug in hibernate implementation. Do we already have a JIRA for the same?
I couldnt find it in JIRA search though.

Thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.