Re: hibernate - what is wrong??
- From: IchBin <weconsul@xxxxxxx>
- Date: Sat, 03 Jun 2006 16:08:24 -0400
konrad.kaminski@xxxxxxxxx wrote:
Hey,
could you tell me what is wrong with this code:
first class:
package test.beans;
public class Bean1 {
private long bean1id;
private String value;
private Bean2 bean2;
public Bean2 getBean2() {
return bean2;
}
public void setBean2(Bean2 b2) {
this.bean2 = b2;
}
public long getBean1id() {
return bean1id;
}
public void setBean1id(long bean1id) {
this.bean1id = bean1id;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
second class:
package test.beans;
public class Bean2 {
private long bean2id;
private long bean2bean1id;
private double price;
public long getBean2bean1id() {
return bean2bean1id;
}
public void setBean2bean1id(long bean2bean1id) {
this.bean2bean1id = bean2bean1id;
}
public long getBean2id() {
return bean2bean1id;
}
public void setBean2id(long bena2id) {
this.bean2bean1id = bena2id;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
}
mapping files:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="test.beans">
<class name="Bean1" table="bean1">
<id name="bean1id" type="long" column="bean1id">
<generator class="native" />
</id>
<set name="bean2" inverse="true" cascade="all">
<key column="bean2_bean1id" />
<one-to-many class="Bean2"/>
</set>
<property name="value">
<column name="value" />
</property>
</class>
</hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="test.beans">
<class name="Bean2" table="bean2">
<id name="bean2id" type="long" column="bean2id">
<generator class="native" />
</id>
<property name="price">
<column name="price" />
</property>
<many-to-one name="bean2bean1id" column="bean2_bean1id" />
</class>
</hibernate-mapping>
and main class:
package test;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import test.beans.Bean1;
import test.beans.Bean2;
public class MyClass {
public static void main(String[] args) {
MyClass a = new MyClass();
a.go();
}
private void go() {
SessionFactory sf = new
Configuration().configure().buildSessionFactory();
Session session = sf.openSession();
session.beginTransaction();
Bean1 b1 = new Bean1();
b1.setValue("test");
Bean2 b2 = new Bean2();
b2.setPrice(12.12);
b1.setBean2(b2);
session.save(b1);
session.getTransaction().commit();
}
}
Be nicer if you told up what your error is..
--
Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________
'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
.
- Follow-Ups:
- Re: hibernate - what is wrong??
- From: konrad . kaminski
- Re: hibernate - what is wrong??
- References:
- hibernate - what is wrong??
- From: konrad . kaminski
- hibernate - what is wrong??
- Prev by Date: hibernate - what is wrong??
- Next by Date: Re: hibernate - what is wrong??
- Previous by thread: hibernate - what is wrong??
- Next by thread: Re: hibernate - what is wrong??
- Index(es):
Relevant Pages
|