Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

adding more than one entry

 
Samanthi perera
Ranch Hand
Posts: 510
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is my config file

this is my employee class


this is my main class


this is the query i used to make table


this code is working .
But my problem is when i try to reun this main file it gives error.



i need to run this file and enter data more than one time.what are the changes i have to done?
 
Vijitha Kumara
Bartender
Posts: 3908
9
Chrome Fedora Hibernate
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Samanthi perera wrote:

this code is working .
But my problem is when i try to reun this main file it gives error.
i need to run this file and enter data more than one time.what are the changes i have to done?

Because you are using the same id value for each run. You should change the id each time you run the application.
 
Samanthi perera
Ranch Hand
Posts: 510
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found we have to use generator element.
can you tell me how to chang this class with generator element?
 
Vijitha Kumara
Bartender
Posts: 3908
9
Chrome Fedora Hibernate
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may use something like,

Check the JPA specification/documentation of the provider for more information and relevant annotations.
 
Samanthi perera
Ranch Hand
Posts: 510
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
where to put this value?
 
Vijitha Kumara
Bartender
Posts: 3908
9
Chrome Fedora Hibernate
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should annotate the Id field of your bean with this and some annotations for sequences etc.. I suggest you read the JPA Specification for more details.
 
ishan dave
Ranch Hand
Posts: 39
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Samanthi,

the problem is at
# SEVERE: Duplicate entry '5' for key 1
# Jan 30, 2010 10:09:16 AM org.hibernate.event.def.AbstractFlushingEventListener performExecutions
# SEVERE: Could not synchronize database state with session
# org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update

for resolving this you need to change the id of you entity as you said. for that you need to use
@GeneratedValue annotation for generating your id every time you persist them.

it should be like this
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
Integer id;

this way your ids will be generated automatically, there some other strategies also available for Id generation like
Identity, Sequence and Table
here what I think is some are database dependent so Table strategy is the best one and most suitable to my requirement.

if you want know more about other attributes then please try some googling like Id generation in JPA or refer the docs or post reply and I will get back with more details

thank you,
ishaan


 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Once the question is answered it's not really necessary to answer it again.
 
Samanthi perera
Ranch Hand
Posts: 510
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i change class


but if i comment @GeneratedValue(strategy = GenerationType.AUTO) line it is working .
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic