-->
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.  [ 4 posts ] 
Author Message
 Post subject: About making primary key table object.
PostPosted: Sun Feb 15, 2009 11:19 pm 
Newbie

Joined: Thu Feb 12, 2009 7:28 am
Posts: 3
Hi,

In the Hibernate,I am aware that, to insert data in foreign key in the table,
first we have to make the object of primary key table, then we can use that object as foriegn key for inserting data in another table.

but the problem is that, if i want to insert the 1 million record at a time, then each time i should first create the object of primary key table.
so the 1 million primary key table's objects are created.

so, is there any way to aviod of creating 1 million primary key table's objects for inserting 1 million records in foreign key table?

Happy Coding!! :-)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 16, 2009 12:54 am 
Expert
Expert

Joined: Fri Jan 30, 2009 1:47 am
Posts: 292
Location: Bangalore, India
I don't really get your problem. Why will you insert data into a table just because it is referenced by a different table.

Lets say A.fid references B.id

But if you think that for a row in A its not related to any rows of B then in A just keep the foreign key column null.

Also its not required that each row in A should have a corresponding row in B. If the relation is many to one then one row in B can be referenced by all the rows in A. So if you want to insert 1 million rec in A then you dont have to insert 1 million records in B.

_________________
Regards,
Litty Preeth


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 16, 2009 1:12 am 
Newbie

Joined: Thu Feb 12, 2009 7:28 am
Posts: 3
littypreethkr wrote:
I don't really get your problem. Why will you insert data into a table just because it is referenced by a different table.

Lets say A.fid references B.id

But if you think that for a row in A its not related to any rows of B then in A just keep the foreign key column null.

Also its not required that each row in A should have a corresponding row in B. If the relation is many to one then one row in B can be referenced by all the rows in A. So if you want to insert 1 million rec in A then you dont have to insert 1 million records in B.


Hi littypreethkr,

I think you are not understanding my problem.
I am not trying to insert the record in both primary and foreign key table.

my problem is like this:

for example:

my TblB pojo is like this:

public String name;
public date sDate;
public com.example.TblA tblA;

Public TblB(com.example.TblA tblA,String name,String sDate){
this.tblA = tblA;
this.name = name;
this.sDate = sDate;
}


now in HibernateDao Class....

TblA tblA = (TblA) hibernateTemplate.get(bean.getId());
TblB tblB = new TblB(tblA,"Information", new Date());
hibernateTemplate.save(tblB);

now here TblA has a primary key named as 'Id'.
TblB has a foreign key name 'id' with many to one relationship.

now if i want to insert 1 million record in TblB, for that i should first create the object of TblA.
so that the object of TblA is also created 1 million times.

So Is there any way so that i can remove that dependency?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 16, 2009 1:19 am 
Expert
Expert

Joined: Fri Jan 30, 2009 1:47 am
Posts: 292
Location: Bangalore, India
If the foreign key field is a null-able column then you can do this this:

Code:
TblB tblB = new TblB(null,"Information", new Date());
hibernateTemplate.save(tblB);


Otherwise as the relation is a many to one, you can relate an existing TblA object to the new TblB records which you create.

_________________
Regards,
Litty Preeth


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.