package org.hibernate.test.annotations.onetoone.referencedcolumnname;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.junit.Test;

public class OneToOne_referencedColumnName_Test extends org.hibernate.test.annotations.TestCase {
 
 @Test
 public void testNothing(){
  
 }
 
 @Test
 public void testOneToOneWithReferencedColumnName(){
  Session s;
  Transaction tx;
  s = openSession();
  tx = s.beginTransaction();
  
  HI hi = new HI();
  hi.setId("1");
  s.save(hi);
  
  H h = new H();
  h.setId("2");
  h.setObjId("h2");
  s.save(h);
  hi.setH(h);

  tx.commit();
  s = openSession();
  tx = s.beginTransaction();
  
  h = (H) s.get(H.class, h.getId());
  assertNotNull(h);
  
  assertNotNull(h.getHiObject());
  assertEquals(h.getHiObject().getId(),hi.getId());
  assertEquals(h.getId(),h.getHiObject().getH().getId());
  
  tx.commit();
  s.clear();
  tx = s.beginTransaction();
  
  hi = (HI) s.get(HI.class, hi.getId());
  assertNotNull(hi);
  
  assertNotNull(hi.getH());
  assertEquals(hi.getId(),hi.getId());
  assertEquals(hi.getId(),hi.getH().getHiObject().getId());
  
  s.delete(hi.getH());
  s.delete(hi);
  tx.commit();
  s.close();
 }
 
 @Override
 protected Class<?>[] getAnnotatedClasses() {
  return new Class<?>[]{H.class,HI.class};
 }

 
 
}

Add a code snippet to your website: www.paste.org