-->
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.  [ 6 posts ] 
Author Message
 Post subject: URGENTTTTTT Problem with ManyToMany
PostPosted: Fri Jul 07, 2006 4:38 pm 
Newbie

Joined: Thu Jul 21, 2005 10:17 am
Posts: 17
I have a problem in my manyToMany relationship...


I try to run this EJB-QL:

"DELETE from Grupo grp where grp.ugUsuario.usId = 1"


But the server throw an exception:


[#|2006-07-07T17:33:33.652-0300|INFO|sun-appserver-pe9.1|javax.enterprise.system.container.ejb|_ThreadID=15;_ThreadName=p: thread-pool-1; w: 3;|
javax.ejb.EJBException
at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:3730)
at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:3630)
at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:3431)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1247)
at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:197)
at com.sun.ejb.containers.EJBObjectInvocationHandlerDelegate.invoke(EJBObjectInvocationHandlerDelegate.java:67)
at $Proxy58.removeGruposDoUsuario(Unknown Source)
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:585)
at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:121)
at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatchToServant(CorbaServerRequestDispatcherImpl.java:650)
at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatch(CorbaServerRequestDispatcherImpl.java:193)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequestRequest(CorbaMessageMediatorImpl.java:1705)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:1565)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleInput(CorbaMessageMediatorImpl.java:947)
at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:178)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:717)
at com.sun.corba.ee.impl.transport.SocketOrChannelConnectionImpl.dispatch(SocketOrChannelConnectionImpl.java:473)
at com.sun.corba.ee.impl.transport.SocketOrChannelConnectionImpl.doWork(SocketOrChannelConnectionImpl.java:1270)
at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:479)
Caused by: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute update query
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:567)
at org.hibernate.ejb.QueryImpl.executeUpdate(QueryImpl.java:46)
at br.com.escriba.compartilhado.ejbx.AbstractEscribaSessionBean.executeCommand(AbstractEscribaSessionBean.java:152)
at br.com.escriba.escribauser.session.GrupoSessionBean.removeGruposDoUsuario(GrupoSessionBean.java:221)
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:585)
at com.sun.enterprise.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1050)
at com.sun.enterprise.security.SecurityUtil.invoke(SecurityUtil.java:165)
at com.sun.ejb.containers.BaseContainer.invokeTargetBeanMethod(BaseContainer.java:2766)
at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:3847)
at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:190)
... 17 more
Caused by: org.hibernate.exception.SQLGrammarException: could not execute update query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:84)
at org.hibernate.hql.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:391)
at org.hibernate.engine.query.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:259)
at org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:1134)
at org.hibernate.impl.QueryImpl.executeUpdate(QueryImpl.java:94)
at org.hibernate.ejb.QueryImpl.executeUpdate(QueryImpl.java:43)
... 28 more
Caused by: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where us_id=2' at line 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:930)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2816)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1530)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1620)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3025)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:937)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1178)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1095)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1080)
at com.mysql.jdbc.jdbc2.optional.PreparedStatementWrapper.executeUpdate(PreparedStatementWrapper.java:834)
at org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:75)
... 33 more
|#]






Hibernate version: 3.1.2 and 3.2.0CR2

Mapping documents:
@Entity
@Table(name = "compartilhado.grupo")
public class Grupo implements Serializable {

@Id
@Column(name = "gr_id", nullable = false)
private Integer grId;
@Column(name = "gr_nome", nullable = false)
private String grNome;
@JoinTable(name = "compartilhado.usuario_grupo", joinColumns = {@JoinColumn(name = "ug_grupo", referencedColumnName = "gr_id")}, inverseJoinColumns = {@JoinColumn(name = "ug_usuario", referencedColumnName = "us_id")})
@ManyToMany(fetch=FetchType.EAGER)
private java.util.Set <Usuario> ugUsuario = new HashSet<Usuario>();

gets... sets...


@Entity
@Table(name = "compartilhado.usuario")
public class Usuario implements Serializable {

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "us_id", nullable = false)
private Integer usId;
@Column(name = "us_nome", nullable = false)
private String usNome;
@ManyToMany(fetch=FetchType.EAGER,mappedBy = "ugUsuario")
private java.util.Set <Grupo> ugGrupo = new HashSet<Grupo>();

gets... sets...




Code between sessionFactory.openSession() and session.close():

em.createQuery("DELETE from Grupo grp where grp.ugUsuario.usId =1").execute();


Name and version of the database you are using:

MySQL 5.0.20 with Connector/J 5.0.0 Beta


The generated SQL (show_sql=true):

none, only print error


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 07, 2006 4:39 pm 
Newbie

Joined: Thu Jul 21, 2005 10:17 am
Posts: 17
With oracle TOPLINK works fine.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 08, 2006 1:10 pm 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
Where did this 2 come from?
Quote:
for the right syntax to use near 'where us_id=2' at line 1


See the actual sql query - turn on sql log.


Top
 Profile  
 
 Post subject: Re: URGENTTTTTT Problem with ManyToMany
PostPosted: Sun Jul 09, 2006 6:26 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
chun wrote:
"DELETE from Grupo grp where grp.ugUsuario.usId = 1"

@JoinTable(name = "compartilhado.usuario_grupo", joinColumns = {@JoinColumn(name = "ug_grupo", referencedColumnName = "gr_id")}, inverseJoinColumns = {@JoinColumn(name = "ug_usuario", referencedColumnName = "us_id")})
@ManyToMany(fetch=FetchType.EAGER)
private java.util.Set <Usuario> ugUsuario = new HashSet<Usuario>();


This query is definitively not valid. If this works on Toplink, please report a bug to the Toplink team. you must not access a single property of a collection through a dotted operation (ugUsuario.usId), this simply does not make sense.
Use a subselect and a the join keyword.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 10, 2006 7:28 am 
Newbie

Joined: Thu Jul 21, 2005 10:17 am
Posts: 17
alesj wrote:
Where did this 2 come from?
Quote:
for the right syntax to use near 'where us_id=2' at line 1


See the actual sql query - turn on sql log.


delete is with ID =1 not id =2... sorry....


Top
 Profile  
 
 Post subject: Re: URGENTTTTTT Problem with ManyToMany
PostPosted: Mon Jul 10, 2006 7:30 am 
Newbie

Joined: Thu Jul 21, 2005 10:17 am
Posts: 17
emmanuel wrote:
chun wrote:
"DELETE from Grupo grp where grp.ugUsuario.usId = 1"

@JoinTable(name = "compartilhado.usuario_grupo", joinColumns = {@JoinColumn(name = "ug_grupo", referencedColumnName = "gr_id")}, inverseJoinColumns = {@JoinColumn(name = "ug_usuario", referencedColumnName = "us_id")})
@ManyToMany(fetch=FetchType.EAGER)
private java.util.Set <Usuario> ugUsuario = new HashSet<Usuario>();


This query is definitively not valid. If this works on Toplink, please report a bug to the Toplink team. you must not access a single property of a collection through a dotted operation (ugUsuario.usId), this simply does not make sense.
Use a subselect and a the join keyword.



Ok... but if i want to delete the "usuario_grupo" links of "usuario->grupo" what SQL i will have ?

i'm not undestang the left join for delete clause...


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

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.