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
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.
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.
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