Joined: Tue Dec 30, 2008 6:08 am Posts: 6 Location: India				
			 | 
			
				
				
					| 
					
						 According to java persistence with hibernate 
 i have two classes 
 Let it be  
 1. public class Account { 
 private long id; 
 private String type; 
 private Customer customer; 
 
 mapping file--<class name="Account" table="ACCOUNT"> 
 <id name="id" column="accid"> 
 <generator class="foreign"> 
 <param name="property">customer</param> 
 </generator> 
 
 </id> 
 <property name="type" column="TYPE" type="string"/> 
 <one-to-one name="customer" class="Customer" constrained="true"/> 
 </class> 
 
 
 2. public class Customer { 
 private long id; 
 private String name; 
 private Account account; 
 
 mapping file--<class name="Customer" table="CUSTOMER"> 
 <id name="id" type="long"> 
 <generator class="native"/> 
 </id> 
 <property name="name" type="string" column="NAME"/> 
 <one-to-one name="account" class="Account" cascade="save-update"/> 
 </class> 
 
 hibernate-cfg.xml 
 <property name="hibernate.dialect">net.sf.hibernate.dialect.OracleDialect</property> 
 <property name="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</property> 
 <property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:ora9i</property> 
 <property name="hibernate.connection.username">user</property> 
 <property name="hibernate.connection.password">password</property> 
 <property name="hibernate.show_sql">true</property> 
 
 <property name="hibernate.jdbc.batch_size">50</property> 
 
 <property name="hibernate.c3p0.min_size">10</property> 
 <property name="hibernate.c3p0.max_size">20</property> 
 <property name="hibernate.c3p0.idle_test_period">300</property> 
 <property name="hibernate.c3p0.timeout">600</property> 
 <property name="hibernate.c3p0.acquire_increment">5</property> 
 
 
 
 <mapping resource="Customer.hbm.xml"/> 
 <mapping resource="Account.hbm.xml"/> 
 
 Test.java 
 public static void main(String[] args) throws HibernateException { 
 
 Session session=ApplicationSession.getInstance().getSession();	
 
 Transaction tx=session.beginTransaction(); 
 
 Customer customer=new Customer(); 
 customer.setName("marcuri"); 
 Account account=new Account(); 
 account.setType("saving"); 
 
 customer.setAccount(account); 
 account.setCustomer(customer); 
 session.save(customer); 
 
 
 tx.commit(); 
 session.close(); 
 show-SQL --- 
 Hibernate: select hibernate_sequence.nextval from dual 
 Hibernate: insert into CUSTOMER (NAME, id) values (?, ?) 
 Hibernate: update ACCOUNT set TYPE=? where accid=? 
 
 Problem is its not inserting the respective Account in the account table  only the customer is inserted 
 how can i make this work Is there any problem with my mapping????  waiting for a response 
					
  
						
					 | 
				 
				 
			 |