Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem while One to One Relationship

 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a problem while performing One to One RelationShip as shown below.

If there are four rows in shipment table the last row cannot get order name
i.e s.getOrderPOJO().getOrderName() throws Exception for last row.
I am not able to understand why.

Thanks
 
nitin pokhriyal
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are using one-to-one bidirectional mapping right? you are passing shipment object in order object but not the order object in shipment. I am not sure whether this will work or not.

public void orderShipment(){
Shipment s=new Shipment();
s.setCity("Mumbai");
s.setZipCode("1");
Order o=new Order();
o.setOrderName("S/W Order");
o.setShipment(s);
s.setOrderName(o); ////////Line this can be one issue.
em.persist(o);
}

Regards,
Nitin
 
Pedro Erencia
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gowher.
I've test your code whithout problems... making an hbm2ddl auto.
I've run the client several times and received correct Order.
 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pedro Erencia

Can you tell me which application server and IDE you are using.
What is hbm2ddl?

Thanks
 
Pedro Erencia
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
eclipse 3.3 and JBoss 4.2.2
hbm2ddl is a property you can place in your persistence.xml to create the database tables automatically from the entity beans.

<property name="hibernate.hbm2ddl.auto">create</property>
 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using Netbeans5.5 and Sun application server 9.0

Inside persistence.xml
----------------------
<properties>
<property name="toplink.ddl-generation" value="create-tables"/>
</properties>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic