reset password
Author Message
talisunep
Posts: 140
Posted 03:28 May 10, 2013 |

professor my spring not commiting form values to database like on adding a new user,

 do i need to do a entityManager.flush(); after merge in DAOimplementation?

@Override
@Transactional
public User saveUser(User user) {

return entityManager.merge(user);
}

my add user fileds are not showing up in my database and i dont get any errors after hitting the submit button it redirects to the redirected page. Is this a case where the queries are still not committed due to some JPA configuration? where do you think i could be going wrong as i have checked the repository code and i seem to do the code right...?
 

cysun
Posts: 2935
Posted 08:13 May 10, 2013 |

The saveUser() method looks fine. Do a little debugging to see if it was actually called.

talisunep
Posts: 140
Posted 08:15 May 10, 2013 |

in this case since i am not getting any errors to debug what do you think will be the best way to go about debugging to see if my method has been implemented?

talisunep
Posts: 140
Posted 08:26 May 10, 2013 |

i re-did the class example done in class... everything was done as per the class lecture but its still not updating the postgres database...
after adding add user it redirects to the user.html which i specified in the controller..
>do we need to make any changes to the postgres database settings?
 

cysun
Posts: 2935
Posted 08:27 May 10, 2013 |
talisunep wrote:

in this case since i am not getting any errors to debug what do you think will be the best way to go about debugging to see if my method has been implemented?


LIke I said, first make sure the method is actually called. You can set a break point in the method then use Eclipse's debugger, or just add some logging statement in the method.

If the method is indeed called, then it must have something to do with transaction management. Since you do have the @Transactional annotation, so check a) if you imported the correct annotation (should be org.springframework.transaction.annotation.Transactional), and b) if you have <tx:annotation-driven /> in applicationContext.xml (without it @Transactional will be ignored).

cysun
Posts: 2935
Posted 08:30 May 10, 2013 |
talisunep wrote:

i re-did the class example done in class... everything was done as per the class lecture but its still not updating the postgres database...
after adding add user it redirects to the user.html which i specified in the controller..
>do we need to make any changes to the postgres database settings?

Check out the springmvc example from the repository (the pieces tag) and run it. If it works, your postgresql db is fine.

talisunep
Posts: 140
Posted 13:39 May 10, 2013 |

professor i checked 

a.the correct annotation is imported... org.springframework.transaction.annotation.Transactional

b. also the 
<tx:annotation-driven /> in applicationContext.xml is present

c. i also did logging statement in the method on the controller/userDao/userDao Implementation
i did a


System.out.println(user.getFirstName()+"from jpa");

it prints out the correct input form userName in the console



@Override
@Transactional

public User saveUser(User user) {
System.out.println(user.getFirstName()+"from jpa");
return entityManager.merge(user);

}

i still cant figure out why it wont commit to the database..? Do you think that i am still missing some configuration in my SPRING set up?

 

cysun
Posts: 2935
Posted 15:33 May 10, 2013 |

Have you tried the springmvc code? If the sample code works, it means there's something wrong with your Spring bean files; if it doesn't work, then maybe there's something wrong with PostgreSQL. I remember somebody had some weird problem with MySQL on MAC in CS320 (was that you?), and restarting the computer fixed it.

talisunep
Posts: 140
Posted 15:40 May 10, 2013 |

the springmvc code also has the same issue..it reads the values from the database but it cant write(merge) values into the database like the example i state above..

yes it was me who had some issues with mac with sql workbench  for homework 1 and it got fixed on a re boot.. ive done the same (rebooted it 2 times) a couple of times but it wont allow me to add values to the database...

cysun
Posts: 2935
Posted 15:45 May 10, 2013 |
talisunep wrote:

the springmvc code also has the same issue..it reads the values from the database but it cant write(merge) values into the database like the example i state above..

yes it was me who had some issues with mac with sql workbench  for homework 1 and it got fixed on a re boot.. ive done the same (rebooted it 2 times) a couple of times but it wont allow me to add values to the database...

If save used to work but all of sudden stopped working, then I can't really help you other than suggesting that you reinstall PostgreSQL.

If save never worked (or you never tried before), it may have something to do with the JDBC driver. Try an older version of the driver (i.e. change the dependency) and see if it fixes the problem.

talisunep
Posts: 140
Posted 20:06 May 10, 2013 |

i reinstalled postgre on my mac.. re set up the database
i re imported springmvc validation and its commiting to the database.. it adds a new user it works however

but on my app  still dosnt allow merge to write to the database... is this related in anyway to the database entities or design? but even in this case it should give errors which it is not giving? all the set up pom.xml , web.xml , application context /servlet.xml are the same....

Last edited by talisunep at 20:08 May 10, 2013.
talisunep
Posts: 140
Posted 20:08 May 10, 2013 |

also wanted to mention that the input values from .GET are printing out values of add user till the .merge method in the userDao implementatton...