-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: problem with foreign generator
PostPosted: Tue Dec 30, 2008 7:42 am 
Newbie

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


Top
 Profile  
 
 Post subject: Re: problem with foreign generator
PostPosted: Tue Dec 30, 2008 10:48 am 
Newbie

Joined: Tue Dec 30, 2008 6:08 am
Posts: 6
Location: India
[quote="marcuri"]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>

............


there is no problem with this mapping
actually i was using hibernate2.0


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.