Hi,

I am using postgres JDBC driver: PostgreSQL Native Driver, version: PostgreSQL 
8.1devel JDBC3 with SSL (build 400) and JBoss4.0.4GA.

Working through the Mastering EJB3 book from Wiley I came to Java persistence 
and the first example @Onetoone relationships. having copied the example from 
the book I get two tables auto generated on deployment but instead of a foriegn 
key mapping I get the second entity "shipment" embedded in the first as a 
bytea. The tables generated and the POJOs entities are given below.

When persisting the first entity I indeed get the second entities data embedded 
in the first and the second entity table is empty!!

It must be something pretty simple!

CREATE TABLE order1to1
  | (
  |   id int4 NOT NULL,
  |   ordername varchar(255),
  |   shipment bytea,
  |   CONSTRAINT order1to1_pkey PRIMARY KEY (id)
  | ) 
  | 
  | CREATE TABLE shipment1to1
  | (
  |   id int4 NOT NULL,
  |   city varchar(255),
  |   zipcode varchar(255),
  |   CONSTRAINT shipment1to1_pkey PRIMARY KEY (id)
  | ) 
  | 
the java is as follows ..

package uk.hsoft;
  | 
  | import java.io.Serializable;
  | 
  | import javax.persistence.CascadeType;
  | import javax.persistence.Entity;
  | import javax.persistence.Id;
  | import javax.persistence.OneToOne;
  | 
  | @Entity(name = "Order1to1")
  | public class OneToOneUni implements Serializable {
  | 
  |     /**
  |      * 
  |      */
  |     private static final long serialVersionUID = -8964029485294348182L;
  | 
  |     @Id
  |     private int id;
  | 
  |     private String orderName;
  | 
  |     private Shipment shipment;
  | 
  |     public OneToOneUni() {
  |             super();
  |             id = (int) System.nanoTime();
  |     }
  | 
  |     public String getOrderName() {
  |             return orderName;
  |     }
  | 
  |     public void setOrderName(String orderName) {
  |             this.orderName = orderName;
  |     }
  | 
  |     @OneToOne(cascade = { CascadeType.PERSIST })
  |     public Shipment getShipment() {
  |             return shipment;
  |     }
  | 
  |     public void setShipment(Shipment shipment) {
  |             this.shipment = shipment;
  |     }
  | 
  |     public int getId() {
  |             return id;
  |     }
  | }


  | package uk.hsoft;
  | 
  | import java.io.Serializable;
  | 
  | import javax.persistence.Entity;
  | import javax.persistence.Id;
  | 
  | @Entity(name="Shipment1to1")
  | 
  | public class Shipment implements Serializable {
  |     
  |     @Id
  |     private int id;
  |     private String city;
  |     private String zipCode;
  | 
  |     public Shipment() {
  |             super();
  |             id = (int)System.nanoTime();
  |     }
  | 
  |     /**
  |      * 
  |      */
  |     private static final long serialVersionUID = -2447771500427072057L;
  | 
  |     public int getId() {
  |             return id;
  |     }
  | 
  |     public String getZipCode() {
  |             return zipCode;
  |     }
  | 
  |     public void setZipCode(String zipCode) {
  |             this.zipCode = zipCode;
  |     }
  | 
  |     public void setCity(String city) {
  |             this.city = city;
  |     }
  | }
  | 

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3969524#3969524

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3969524
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to