Re: hibernate - what is wrong??



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-)
.



Relevant Pages

  • Re: Problem mit BindingSource
    ... Public Class Form36 ... Private Sub Form36_Load(ByVal sender As System.Object, ... private MeinDTO _backup; ... public void BeginEdit() ...
    (microsoft.public.de.german.entwickler.dotnet.datenbank)
  • Re: Can we over-load "+" in Java?
    ... public class Person { ... private String sName; ... private Person leader; ... public void setTeamLeader ...
    (comp.lang.java.programmer)
  • Re: Can we over-load "+" in Java?
    ... public class Person { ... private String sName; ... private Person leader; ... public void setTeamLeader ...
    (comp.lang.java.programmer)
  • Re: Capturing both stdout and stderr of exec-ed process in JTextArea
    ... private static int returnValue = Integer.MIN_VALUE; ... public JtaCommandRunner(JTextArea jta) { ... public void run{ ... public class JtaOutReader implements Runnable { ...
    (comp.lang.java.gui)
  • hibernate - what is wrong??
    ... public class Bean1 { ... private long bean1id; ... private Bean2 bean2; ... public void setBean1id{ ...
    (comp.lang.java.databases)