-->
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.  [ 5 posts ] 
Author Message
 Post subject: SQLException - column name id0_ not found ???
PostPosted: Thu Feb 19, 2004 6:19 am 
Beginner
Beginner

Joined: Thu Feb 19, 2004 6:07 am
Posts: 21
Hi all,

Hibernate newbie here. Was trying out some code and ran into
errors - my postgresql database gives me a SQLException when
I run my code. Says column name id0_ not found - when the
column name is actually id.
Actually I have three beans - foo, bar and snafu and all of them have
the id column - which seemed like a bad idea - since then I changed
the id columns to foo_id, bar_id and snafu_id - but the SQLException
is the same - only difference - now it says column foo_id0_ not found.

Please help.
Below are bean and hbm.xml files.

Code:
<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">


<hibernate-mapping>
    <class name="Foo" table="foo">
        <id name="foo_id" column="foo_id" type="int">
      
            <generator class="assigned"/>
        </id>

        <set name="barSnafus" table="foo_bar_snafu">
            <key column="f_id"/>
            <composite-element class="BarSnafu">
                <many-to-one name="bar" class="Bar" column="b_id"/>
                <many-to-one name="snafu" class="Snafu" column="s_id"/>
            </composite-element>
        </set>
    </class>
</hibernate-mapping>

___________________________________________________________
Code:
<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">


<hibernate-mapping>
    <class name="Bar" table="bar">
       <id name="bar_id" column="bar_id" type="int">
            <generator class="assigned"/>
        </id>
    </class>
</hibernate-mapping>

___________________________________________________________

Code:
<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">


<hibernate-mapping>
    <class name="Snafu" table="snafu">
        <id name="snafu_id" column="snafu_id" type="int">
            <generator class="assigned"/>
        </id>
    </class>
</hibernate-mapping>

___________________________________________________________
Code:
import java.util.Set;
import java.io.Serializable;

public class Foo implements Serializable
{
    protected int foo_id;
    protected Set set;

    public Foo()
    {
    }

    public int getFoo_id()
    {
        return foo_id;
    }

    public void setFoo_id(int foo_id)
    {
        this.foo_id = foo_id;
    }

    public Set getBarSnafus()
    {
        return set;
    }

    public void setBarSnafus(Set set)
    {
        this.set = set;
    }
}

___________________________________________________________


Code:
import java.io.Serializable;



public class Bar implements Serializable
{
    protected int bar_id;

    public Bar()
    {
    }

    public int getBar_id()
    {
        return bar_id;
    }

    public void setBar_id(int bar_id)
    {
        this.bar_id = bar_id;
    }
}

___________________________________________________________
Code:
import java.io.Serializable;



public class Snafu implements Serializable
{
    protected int snafu_id;

    public Snafu()
    {
    }

    public int getSnafu_id()
    {
        return snafu_id;
    }

    public void setSnafu_id(int snafu_id)
    {
        this.snafu_id = snafu_id;
    }
}

___________________________________________________________

Code:
import java.io.Serializable;


public class BarSnafu implements Serializable
{
    protected Bar bar;
    protected Snafu snafu;

    public BarSnafu()
    {
    }

    public Snafu getSnafu()
    {
        return snafu;
    }

    public void setSnafu(Snafu snafu)
    {
        this.snafu = snafu;
    }

    public Bar getBar()
    {
        return bar;
    }

    public void setBar(Bar bar)
    {
        this.bar = bar;
    }

    public String toString()
    {
        return bar.getBar_id() + ", " + snafu.getSnafu_id();
    }
}

___________________________________________________________

I'd be very much obliged if anyone could point out what mistake I'm making.
Thanks.
sanjeev.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 19, 2004 7:03 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Show the SQL request and the DDL.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 19, 2004 10:49 pm 
Beginner
Beginner

Joined: Thu Feb 19, 2004 6:07 am
Posts: 21
Ok - the ddl is like this:

create table foo(foo_id int);
create table bar(bar_id int);
create table snafu(snafu_id int);
create table foo_bar_snafu(f_id int, b_id int, s_id int);

The problem I figured out is in the sql query string i'm passing.
I corrected the error and it now works beautifully.

select f.* from Foo as f //This wasn't working
select f.id as id0_ from Foo as f // This is.

However I have one more question - I can access the data in tables -
foo, bar and snafu because I loaded these classes onto the config.
But data in table foo_bar_snafu - I'm unable to access - I mean how
would I access it ? I have a relation like BarSnafu but I don't know how it
works - Stupid question - i know - but i'd really like some pointers on
how to get myself up-to-date. Your 2 cents would be of immeasurable value to me.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 20, 2004 5:21 am 
Beginner
Beginner

Joined: Thu Feb 19, 2004 6:07 am
Posts: 21
er - bump.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 20, 2004 7:14 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
http://www.hibernate.org/hib_docs/reference/html_single/#query-language
elements(), indices(), [], etc...

Code:
from foo join foo.barSnafu snafu...

_________________
Emmanuel


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