• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Insert row in a table which having No primary Key

 
gopi nath
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Is there is any method in the hibernate for inserting many rows at a time.
The table is having no primaryKey Id
Thanks in advancejavascript: x()
rolling
 
Pavel Kubal
Ranch Hand
Posts: 360
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wonder if it is even possible to have a table without primary key. I think it's not.

What would be the use of this table?
 
gopi nath
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI
In my case i want to store the Particular values in separate table,From that table i will generate reports without using PK , i will to sort by other fields
 
Pavel Kubal
Ranch Hand
Posts: 360
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I went through documentation and it really seems that you are not required to have a primary key. So I guess, that the mapping will be the same as usual, but without primary key.

And back to your question, have you heard of batch processing?

http://www.hibernate.org/hib_docs/reference/en/html/batch.html
 
gopi nath
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You
Can you say is there is any method to save, without looping as mentioned by your reference document?
 
Pavel Kubal
Ranch Hand
Posts: 360
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would like something like session.save(Collection c) ?

So, as far as I know, there is no such possibility.

http://simoes.org/docs/hibernate-2.1/api/net/sf/hibernate/Session.html
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"gopinath",
Welcome to the JavaRanch.

We're a friendly group, but we do require members to have valid display names.

Display names must be two words: your first name, a space, then your last name. Fictitious names are not allowed.

Please edit your profile and correct your display name since accounts with display names get deleted.
 
Bougnon Kipre
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it is possible to have a table w/o a primary key.
However, hibernate will use what you program in the id
(single field or composite).
As long as you code this in your equals method, you should be fine.
 
Zhao Yutong
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can set the generator of key to "native" ,
that is my suggestion,
i don't enure the method what i say can solve your problom.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bougnon Kipre:
Yes, it is possible to have a table w/o a primary key.
However, hibernate will use what you program in the id
(single field or composite).
As long as you code this in your equals method, you should be fine.


No, this is not the case. You might get away with it, but its not guarenteed to work.

It is possible to define an entity without a primary key in a relational database, but its not a smart thing to do. Without a primary key there is no way to identify a single row. If you can't identify a single row, it can't be used in a relationship, hence is not relational data. Because of this requirement Hibernate does not easily support tables without primary keys. There are work arounds (map all the fields in the the table as a composite key for example) but none are as easy as just giving your table a surrogate key.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic