💡
Our Forums Have Moved
For help with installation, bugs reports or feature requests, please head over to our new forums.
Genuitec Community on GitHub
- This topic has 2 replies, 2 voices, and was last updated 15 years, 8 months ago by
menyarito.
Viewing 3 posts - 1 through 3 (of 3 total)
-
AuthorPosts
-
menyaritoMemberhello,
I configure hibernate in myeclipse following the
next tutorial:
http://www.myeclipseide.com/documentation/quickstarts/hibernate/
running the project it gives me an error message despite
that data is properly recorded in the database
error:Exception in thread "main" java.lang.NullPointerException at modele.Test.printUser(Test.java:96) at modele.Test.listUser(Test.java:55) at modele.Test.main(Test.java:15)my class Test_hibernate.java:
package mypackage; import org.hibernate.Transaction; public class tesett { public static void main(String[] args) { addUser(); listUser(); changeUser(); } private static void addUser() { User user = new User(); user.setId(1); user.setUsername("jdoe"); user.setPassword("1234"); user.setFirstName("John"); user.setLastName("Doe"); user.setDateCreated(System.currentTimeMillis()); UserDAO dao = new UserDAO(); Transaction tx = dao.getSession().beginTransaction(); dao.save(user); tx.commit(); dao.getSession().close(); } private static void listUser() { UserDAO dao = new UserDAO(); User user = dao.findById(1); printUser("Printing User, ", user); dao.getSession().close(); } private static void changeUser() { UserDAO dao = new UserDAO(); User user = dao.findById(1); user.setUsername("jsmith"); user.setPassword("abcd"); user.setFirstName("Jane"); user.setLastName("Smith"); Transaction tx = dao.getSession().beginTransaction(); dao.save(user); tx.commit(); User updatedUser = dao.findById(1); printUser("Printing Updated User, ", updatedUser); dao.getSession().close(); } private static void printUser(String extraText, User user) { System.out.println(extraText + " User[Username: " + user.getUsername() + ", Password: " + user.getPassword() + ", First Name: " + user.getFirstName() + ", Last Name: " + user.getLastName() + "]"); } }thank you in advance
December 14, 2010 at 3:12 am #313268menyarito,
I could not replicate it at my end.
This should be due to a wrong value being passed to findById().
Can you recheck if you are passing the proper id to the findById() for printUser?
Also check if the dao.findById() is returning a valid user object or not.December 14, 2010 at 6:06 am #313270
menyaritoMembersuper, thank you very much
-
AuthorPosts
Viewing 3 posts - 1 through 3 (of 3 total)

