I have a problem with session.load when i run:
Event anEvent = (Event) session.load(Event.class, new Long(2603));
this exception will thrown:
java.lang.NullPointerException
at org.hibernate.tuple.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:372)
at org.hibernate.persister.entity.AbstractEntityPersister.createProxy(AbstractEntityPersister.java:3121)
at org.hibernate.event.def.DefaultLoadEventListener.createProxyIfNecessary(DefaultLoadEventListener.java:232)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:173)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:87)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:869)
at org.hibernate.impl.SessionImpl.load(SessionImpl.java:788)
at org.hibernate.impl.SessionImpl.load(SessionImpl.java:781)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:292)
at $Proxy0.load(Unknown Source)
at events.EventManager.createAndStorePerson(EventManager.java:61)
at events.EventManager.main(EventManager.java:26)
the complete code is:
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
Person thePerson = new Person();
thePerson.setFirstname(firstName);
thePerson.setLastname(lastName);
Event anEvent = (Event) session.load(Event.class, new Long(2603));
thePerson.getEvents().add(anEvent);
session.save(thePerson);
session.getTransaction().commit();
but, if i write code like this, it works well!!!
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
Person thePerson = new Person();
thePerson.setFirstname(firstName);
thePerson.setLastname(lastName);
List result = session.createQuery("from Event where id = 2603").list(); Event anEvent = (Event) result.get(0);
thePerson.getEvents().add(anEvent);
session.save(thePerson);
session.getTransaction().commit();
What's the problem?????????????????
Thanks for help.
|