[EJB 3.0] - Many to Many realtionship question
by EladKatz
Hi,
I'm using a manyToMany relationship in my project and I have a question:
Is it possible to update the relationship from both sides?
I'll show you an example of what i mean:
| @Entity
| public class Student {
| @Id @GeneratedValue(strategy=GenerationType.IDENTITY)
| private int id;
| private String name;
|
| @ManyToMany
| @JoinTable(name="Student_Dept",
| joinColumns=@JoinColumn(name="Stut_ID"),
| inverseJoinColumns=@JoinColumn(name="DEPT_ID"))
| private Collection<Department> departments;
| public Student() {
| departments = new ArrayList<Department>();
| }
| ...
| public Collection<Department> getDepartments() {
| return departments;
| }
|
| public void setDepartment(Collection<Department> departments) {
| this.departments = departments;
| }
|
| @Entity
| public class Department {
| @Id @GeneratedValue(strategy=GenerationType.IDENTITY)
| private int id;
| private String name;
|
| @ManyToMany(mappedBy="departments")
| private Collection<Student> students;
|
| public Department(){
| students = new ArrayList<Student>();
| }
| ...
| public Collection<Student> getStudents() {
| return students;
| }
|
| public void setStudent(Collection<Student> students) {
| this.students = students;
| }
|
Given that, In my main.java I can do this:
| Department dept = new Department();
| ...
| dept.addStudent(student1);
| em.persist(dept);
|
and it works
but if i try it the other way around
| student.addDept(dept1);
|
it fails to update the database (no exception or anything - the changes simply do not reflect in the db)
is that because i have to do it from one side only?
note:
This example is not my code but was taken from: http://www.java2s.com/Tutorial/Java/0355__JPA/ManyToManyJoinTableJoinInve...
it is similar enough though that you can use it as a reference.
Thanks,
Elad Katz
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4249486#4249486
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4249486
16 years, 10 months
[JBoss Messaging] - javax.jms.IllegalStateException: Cannot find session with id
by mmoorcroft
JBoss 4.2.3GA + Messaging 1.4.2.GA
I keep seeing the following stack trace in our server.log.
2009-08-11 00:02:57,310 ERROR [org.jboss.messaging.util.ExceptionUtil] ConnectionEndpoint[leg72-2xa188yf-1-xz6nb3yf-03cvpk-k562ka] sendTransaction [hqm72-a5i788yf-1-xz6nb3yf-03cvpk-k562ka]
javax.jms.IllegalStateException: Cannot find session with id 1fg72-oxa188yf-1-xz6nb3yf-03cvpk-k562ka
at org.jboss.jms.server.endpoint.ServerConnectionEndpoint.processTransaction(ServerConnectionEndpoint.java:835)
at org.jboss.jms.server.endpoint.ServerConnectionEndpoint.sendTransaction(ServerConnectionEndpoint.java:489)
at org.jboss.jms.server.endpoint.advised.ConnectionAdvised.org$jboss$jms$server$endpoint$advised$ConnectionAdvised$sendTransaction$aop(ConnectionAdvised.java:101)
at org.jboss.jms.server.endpoint.advised.ConnectionAdvised$sendTransaction_N3268650789275322226.invokeNext(ConnectionAdvised$sendTransaction_N3268650789275322226.java)
at org.jboss.jms.server.container.SecurityAspect.handleSendTransaction(SecurityAspect.java:195)
at sun.reflect.GeneratedMethodAccessor278.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.jboss.aop.advice.PerInstanceAdvice.invoke(PerInstanceAdvice.java:121)
at org.jboss.jms.server.endpoint.advised.ConnectionAdvised$sendTransaction_N3268650789275322226.invokeNext(ConnectionAdvised$sendTransaction_N3268650789275322226.java)
at org.jboss.jms.server.container.ServerLogInterceptor.invoke(ServerLogInterceptor.java:105)
at org.jboss.jms.server.endpoint.advised.ConnectionAdvised$sendTransaction_N3268650789275322226.invokeNext(ConnectionAdvised$sendTransaction_N3268650789275322226.java)
at org.jboss.jms.server.endpoint.advised.ConnectionAdvised.sendTransaction(ConnectionAdvised.java)
at org.jboss.jms.wireformat.ConnectionSendTransactionRequest.serverInvoke(ConnectionSendTransactionRequest.java:82)
at org.jboss.jms.server.remoting.JMSServerInvocationHandler.invoke(JMSServerInvocationHandler.java:143)
at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:866)
at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:608)
at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:420)
at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:173)
Can anyone shed some light as to what could be the cause?
Thanks,
Mark
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4249483#4249483
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4249483
16 years, 10 months