Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

adding more than one entry

 
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 4109
72
Hibernate Fedora Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 4109
72
Hibernate Fedora Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
where to put this value?
 
Vijitha Kumara
Bartender
Posts: 4109
72
Hibernate Fedora Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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


 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i change class


but if i comment @GeneratedValue(strategy = GenerationType.AUTO) line it is working .
 
I brought this back from the farm where they grow the tiny ads:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic