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.