-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Many-to-many relations with attributes - saving to database
PostPosted: Wed Jun 16, 2010 7:46 am 
Newbie

Joined: Wed Jun 16, 2010 7:11 am
Posts: 1
Hi,
i'm new to hibernate and have problems by saving a man-to-many object to the database.

Here is a short overview:
Table1: user -> id, ...
Table2: meeting ->id,...
Table3: user_has_meeting ->user_id, meeting_id, status
-> Classes: User, Meeting, UserHasMeetingId, UserHasMeeting

So i've an object User user, Meeting meeting and want to create an new relation between them:

Quote:
UserHasMeetingtId attendee = new UserHasMeetingId(user.getId(), event.getId());
UserHasMeeting attendance = new UserHasMeeting(attendee, user, event, "false");


Now I want to save this object to database:
Quote:
try {
session = HibernateUtil.getSessionFactory().getCurrentSession();
org.hibernate.Transaction tx = session.beginTransaction();
session.save(attendance);
session.flush();
session.refresh(attendance);
tx.commit();
} catch (Exception e) {
e.printStackTrace();
}


The Server log throws following Exception:
Quote:
16.06.2010 13:41:02 org.hibernate.LazyInitializationException <init>
SCHWERWIEGEND: could not initialize proxy - no Session
org.hibernate.LazyInitializationException: could not initialize proxy - no Session
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:57)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111)
at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:150)
at eventmngr.User$$EnhancerByCGLIB$$26e300d8.getEmail(<generated>)
at org.apache.jsp.addAttendee_jsp._jspService(addAttendee_jsp.java:73)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Thread.java:619)


I tried to open a new session:
if (!session.isOpen())
session = HibernateUtil.getSessionFactory().openSession()
But this is not the solution. The object will not saved to the database.

Can you help me? :)
Greezu


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.