-->
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.  [ 5 posts ] 
Author Message
 Post subject: ManyToMany does not work - for me...
PostPosted: Mon Jul 21, 2008 10:34 am 
Newbie

Joined: Thu Feb 14, 2008 1:48 pm
Posts: 15
Hi @all.

I have no idea how I could solve my problem maybe some of you have better and more ideas than mine... Maybe i found a kind of core problem:

First I use the following code ("player0" is already initialized and persited):

Code:
final TeamSessionBeanInterface teamBean = (TeamSessionBeanInterface) ctx.lookup( "ejb/TeamSessionBean" );

final Team team0 = teamBean.persist( new Team() );
team0.setPlayer( new HashSet<Player>() );
team0.getPlayer().add( player0 );
teamBean.update( team0 ); // throws Exception (only if above line is active)

Exception:
Code:
23:37:47,585 WARN  [JDBCExceptionReporter] SQL Error: 0, SQLState: null
23:37:47,585 ERROR [JDBCExceptionReporter] failed batch
23:37:47,585 ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update

"persist" calls:
Code:
em.persist( object );
em.flush();

"update" calls:
Code:
em.merge( object );
em.flush();

Some code from the "Team" and "Player" classes:
Code:
@Entity
public class Team extends SBPObject
{
   @ManyToMany( fetch=FetchType.EAGER, cascade=CascadeType.ALL )
   private Set< Player > player;
   ...
}

Code:
@Entity
public class Player extends NaturalPerson
{
   @ManyToMany( mappedBy = "player", fetch=FetchType.EAGER, cascade=CascadeType.ALL )
   private Set< Team > teams;
   ...
}

Thank you for reading so far :-)
It is really important for me to get this working!
Thank you!
EH


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 23, 2008 4:12 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

could you maybe provide some more information? What exactly happens in teamBean.update() and could you also provide the full stack trace? The org.hibernate.exception.GenericJDBCException is probably just a wrapped exception. There should be more information about the root cause.

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 23, 2008 12:03 pm 
Newbie

Joined: Thu Feb 14, 2008 1:48 pm
Posts: 15
Hi Hardy!

This is the full log about what is happening:
Code:
18:00:03,407 INFO  [STDOUT] Hibernate:
    insert
    into
        SBPObject
        (id, name, DTYPE)
    values
        (null, ?, 'Club')
18:00:03,409 INFO  [STDOUT] Hibernate:
    call identity()
18:00:03,432 INFO  [STDOUT] Hibernate:
    select
        club0_.id as id0_1_,
        club0_.name as name0_1_,
        players1_.club_id as club14_3_,
        players1_.id as id3_,
        players1_.id as id0_0_,
        players1_.birthday as birthday0_0_,
        players1_.firstName as firstName0_0_,
        players1_.gender as gender0_0_,
        players1_.lastName as lastName0_0_,
        players1_.club_id as club14_0_0_
    from
        SBPObject club0_
    left outer join
        SBPObject players1_
            on club0_.id=players1_.club_id
    where
        club0_.id=?
        and club0_.DTYPE='Club'
18:00:03,435 INFO  [STDOUT] Hibernate:
    update
        SBPObject
    set
        name=?
    where
        id=?
18:00:03,475 INFO  [STDOUT] Hibernate:
    insert
    into
        SBPObject
        (id, birthday, firstName, gender, lastName, club_id, DTYPE)
    values
        (null, ?, ?, ?, ?, ?, 'Player')
18:00:03,476 INFO  [STDOUT] Hibernate:
    call identity()
18:00:03,518 INFO  [STDOUT] Hibernate:
    select
        player0_.id as id0_2_,
        player0_.birthday as birthday0_2_,
        player0_.firstName as firstName0_2_,
        player0_.gender as gender0_2_,
        player0_.lastName as lastName0_2_,
        player0_.club_id as club14_0_2_,
        club1_.id as id0_0_,
        club1_.name as name0_0_,
        teams2_.player_id as player2_4_,
        team3_.id as teams1_4_,
        team3_.id as id0_1_
    from
        SBPObject player0_
    left outer join
        SBPObject club1_
            on player0_.club_id=club1_.id
    left outer join
        SBPObject_SBPObject teams2_
            on player0_.id=teams2_.player_id
    left outer join
        SBPObject team3_
            on teams2_.teams_id=team3_.id
    where
        player0_.id=?
        and player0_.DTYPE='Player'
18:00:03,522 INFO  [STDOUT] Hibernate:
    select
        club0_.id as id0_1_,
        club0_.name as name0_1_,
        players1_.club_id as club14_3_,
        players1_.id as id3_,
        players1_.id as id0_0_,
        players1_.birthday as birthday0_0_,
        players1_.firstName as firstName0_0_,
        players1_.gender as gender0_0_,
        players1_.lastName as lastName0_0_,
        players1_.club_id as club14_0_0_
    from
        SBPObject club0_
    left outer join
        SBPObject players1_
            on club0_.id=players1_.club_id
    where
        club0_.id=?
        and club0_.DTYPE='Club'
18:00:03,526 INFO  [STDOUT] Hibernate:
    update
        SBPObject
    set
        birthday=?,
        firstName=?,
        gender=?,
        lastName=?,
        club_id=?
    where
        id=?
18:00:03,555 INFO  [STDOUT] Hibernate:
    insert
    into
        SBPObject
        (id, birthday, firstName, gender, lastName, club_id, DTYPE)
    values
        (null, ?, ?, ?, ?, ?, 'Player')
18:00:03,560 INFO  [STDOUT] Hibernate:
    call identity()
18:00:03,577 INFO  [STDOUT] Hibernate:
    select
        player0_.id as id0_2_,
        player0_.birthday as birthday0_2_,
        player0_.firstName as firstName0_2_,
        player0_.gender as gender0_2_,
        player0_.lastName as lastName0_2_,
        player0_.club_id as club14_0_2_,
        club1_.id as id0_0_,
        club1_.name as name0_0_,
        teams2_.player_id as player2_4_,
        team3_.id as teams1_4_,
        team3_.id as id0_1_
    from
        SBPObject player0_
    left outer join
        SBPObject club1_
            on player0_.club_id=club1_.id
    left outer join
        SBPObject_SBPObject teams2_
            on player0_.id=teams2_.player_id
    left outer join
        SBPObject team3_
            on teams2_.teams_id=team3_.id
    where
        player0_.id=?
        and player0_.DTYPE='Player'
18:00:03,579 INFO  [STDOUT] Hibernate:
    select
        club0_.id as id0_1_,
        club0_.name as name0_1_,
        players1_.club_id as club14_3_,
        players1_.id as id3_,
        players1_.id as id0_0_,
        players1_.birthday as birthday0_0_,
        players1_.firstName as firstName0_0_,
        players1_.gender as gender0_0_,
        players1_.lastName as lastName0_0_,
        players1_.club_id as club14_0_0_
    from
        SBPObject club0_
    left outer join
        SBPObject players1_
            on club0_.id=players1_.club_id
    where
        club0_.id=?
        and club0_.DTYPE='Club'
18:00:03,584 INFO  [STDOUT] Hibernate:
    select
        teams0_.player_id as player2_1_,
        teams0_.teams_id as teams1_1_,
        team1_.id as id0_0_
    from
        SBPObject_SBPObject teams0_
    left outer join
        SBPObject team1_
            on teams0_.teams_id=team1_.id
    where
        teams0_.player_id=?
18:00:03,591 INFO  [STDOUT] Hibernate:
    update
        SBPObject
    set
        birthday=?,
        firstName=?,
        gender=?,
        lastName=?,
        club_id=?
    where
        id=?
18:00:03,608 INFO  [STDOUT] Hibernate:
    select
        club0_.id as id0_5_,
        club0_.name as name0_5_,
        players1_.club_id as club14_7_,
        players1_.id as id7_,
        players1_.id as id0_0_,
        players1_.birthday as birthday0_0_,
        players1_.firstName as firstName0_0_,
        players1_.gender as gender0_0_,
        players1_.lastName as lastName0_0_,
        players1_.club_id as club14_0_0_,
        teams2_.player_id as player2_8_,
        team3_.id as teams1_8_,
        team3_.id as id0_1_,
        results4_.team_id as team17_9_,
        results4_.id as id9_,
        results4_.id as id0_2_,
        results4_.game_id as game16_0_2_,
        results4_.points as points0_2_,
        results4_.team_id as team17_0_2_,
        game5_.id as id0_3_,
        game5_.match_id as match15_0_3_,
        game5_.number as number0_3_,
        match6_.id as id0_4_,
        match6_.courtNumber as courtNum8_0_4_,
        match6_.start as start0_4_,
        match6_.stop as stop0_4_,
        match6_.type as type0_4_,
        teams7_.matches_id as matches3_10_,
        teams7_.teams_id as teams1_10_
    from
        SBPObject club0_
    left outer join
        SBPObject players1_
            on club0_.id=players1_.club_id
    left outer join
        SBPObject_SBPObject teams2_
            on players1_.id=teams2_.player_id
    left outer join
        SBPObject team3_
            on teams2_.teams_id=team3_.id
    left outer join
        SBPObject results4_
            on team3_.id=results4_.team_id
    left outer join
        SBPObject game5_
            on results4_.game_id=game5_.id
    left outer join
        SBPObject match6_
            on game5_.match_id=match6_.id
    left outer join
        SBPObject_SBPObject teams7_
            on match6_.id=teams7_.matches_id
    where
        club0_.id=?
        and club0_.DTYPE='Club'
18:00:03,673 INFO  [STDOUT] Hibernate:
    insert
    into
        SBPObject
        (id, DTYPE)
    values
        (null, 'Team')
18:00:03,674 INFO  [STDOUT] Hibernate:
    call identity()
18:00:03,699 INFO  [STDOUT] Hibernate:
    select
        team0_.id as id0_1_,
        matches1_.teams_id as teams1_3_,
        match2_.id as matches3_3_,
        match2_.id as id0_0_,
        match2_.courtNumber as courtNum8_0_0_,
        match2_.start as start0_0_,
        match2_.stop as stop0_0_,
        match2_.type as type0_0_
    from
        SBPObject team0_
    left outer join
        SBPObject_SBPObject matches1_
            on team0_.id=matches1_.teams_id
    left outer join
        SBPObject match2_
            on matches1_.matches_id=match2_.id
    where
        team0_.id=?
        and team0_.DTYPE='Team'
18:00:03,703 INFO  [STDOUT] Hibernate:
    select
        results0_.team_id as team17_3_,
        results0_.id as id3_,
        results0_.id as id0_2_,
        results0_.game_id as game16_0_2_,
        results0_.points as points0_2_,
        results0_.team_id as team17_0_2_,
        game1_.id as id0_0_,
        game1_.match_id as match15_0_0_,
        game1_.number as number0_0_,
        match2_.id as id0_1_,
        match2_.courtNumber as courtNum8_0_1_,
        match2_.start as start0_1_,
        match2_.stop as stop0_1_,
        match2_.type as type0_1_
    from
        SBPObject results0_
    left outer join
        SBPObject game1_
            on results0_.game_id=game1_.id
    left outer join
        SBPObject match2_
            on game1_.match_id=match2_.id
    where
        results0_.team_id=?
18:00:03,705 INFO  [STDOUT] Hibernate:
    select
        player0_.teams_id as teams1_2_,
        player0_.player_id as player2_2_,
        player1_.id as id0_0_,
        player1_.birthday as birthday0_0_,
        player1_.firstName as firstName0_0_,
        player1_.gender as gender0_0_,
        player1_.lastName as lastName0_0_,
        player1_.club_id as club14_0_0_,
        club2_.id as id0_1_,
        club2_.name as name0_1_
    from
        SBPObject_SBPObject player0_
    left outer join
        SBPObject player1_
            on player0_.player_id=player1_.id
    left outer join
        SBPObject club2_
            on player1_.club_id=club2_.id
    where
        player0_.teams_id=?
18:00:03,715 INFO  [STDOUT] Hibernate:
    select
        player0_.id as id0_2_,
        player0_.birthday as birthday0_2_,
        player0_.firstName as firstName0_2_,
        player0_.gender as gender0_2_,
        player0_.lastName as lastName0_2_,
        player0_.club_id as club14_0_2_,
        club1_.id as id0_0_,
        club1_.name as name0_0_,
        teams2_.player_id as player2_4_,
        team3_.id as teams1_4_,
        team3_.id as id0_1_
    from
        SBPObject player0_
    left outer join
        SBPObject club1_
            on player0_.club_id=club1_.id
    left outer join
        SBPObject_SBPObject teams2_
            on player0_.id=teams2_.player_id
    left outer join
        SBPObject team3_
            on teams2_.teams_id=team3_.id
    where
        player0_.id=?
        and player0_.DTYPE='Player'
18:00:03,722 INFO  [STDOUT] Hibernate:
    select
        players0_.club_id as club14_1_,
        players0_.id as id1_,
        players0_.id as id0_0_,
        players0_.birthday as birthday0_0_,
        players0_.firstName as firstName0_0_,
        players0_.gender as gender0_0_,
        players0_.lastName as lastName0_0_,
        players0_.club_id as club14_0_0_
    from
        SBPObject players0_
    where
        players0_.club_id=?
18:00:03,725 INFO  [STDOUT] Hibernate:
    select
        teams0_.player_id as player2_1_,
        teams0_.teams_id as teams1_1_,
        team1_.id as id0_0_
    from
        SBPObject_SBPObject teams0_
    left outer join
        SBPObject team1_
            on teams0_.teams_id=team1_.id
    where
        teams0_.player_id=?
18:00:03,732 INFO  [STDOUT] Hibernate:
    update
        SBPObject
    set
        birthday=?,
        firstName=?,
        gender=?,
        lastName=?,
        club_id=?
    where
        id=?
18:00:03,733 INFO  [STDOUT] Hibernate:
    insert
    into
        SBPObject_SBPObject
        (teams_id, player_id)
    values
        (?, ?)
18:00:03,736 WARN  [JDBCExceptionReporter] SQL Error: 0, SQLState: null
18:00:03,737 ERROR [JDBCExceptionReporter] failed batch
18:00:03,737 ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
   at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
   at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
   at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:251)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:170)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1004)
   at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:304)
   at org.jboss.ejb3.entity.TransactionScopedEntityManager.flush(TransactionScopedEntityManager.java:211)
   at de.sunbeamproject.ejbs.SBPObjectSessionBean.update(SBPObjectSessionBean.java:55)
   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:597)
   at org.jboss.aop.joinpoint.MethodInvocation.invokeTarget(MethodInvocation.java:122)
   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:111)
   at org.jboss.ejb3.EJBContainerInvocationWrapper.invokeNext(EJBContainerInvocationWrapper.java:69)
   at org.jboss.ejb3.interceptors.aop.InterceptorSequencer.invoke(InterceptorSequencer.java:73)
   at org.jboss.ejb3.interceptors.aop.InterceptorSequencer.aroundInvoke(InterceptorSequencer.java:59)
   at sun.reflect.GeneratedMethodAccessor163.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.PerJoinpointAdvice.invoke(PerJoinpointAdvice.java:174)
   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
   at org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor.fillMethod(InvocationContextInterceptor.java:72)
   at org.jboss.aop.advice.org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor_z_fillMethod_27286491.invoke(InvocationContextInterceptor_z_fillMethod_27286491.java)
   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
   at org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor.setup(InvocationContextInterceptor.java:88)
   at org.jboss.aop.advice.org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor_z_setup_27286491.invoke(InvocationContextInterceptor_z_setup_27286491.java)
   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
   at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
   at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
   at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42)
   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
   at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:68)
   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
   at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
   at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:190)
   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
   at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
   at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42)
   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
   at org.jboss.ejb3.security.RoleBasedAuthorizationInterceptorv2.invoke(RoleBasedAuthorizationInterceptorv2.java:201)
   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
   at org.jboss.ejb3.security.Ejb3AuthenticationInterceptorv2.invoke(Ejb3AuthenticationInterceptorv2.java:157)
   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
   at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:41)
   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
   at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
   at org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor.invoke(CurrentInvocationInterceptor.java:67)
   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
   at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:390)
   at org.jboss.ejb3.session.ClassProxyHack._dynamicInvoke(ClassProxyHack.java:52)
   at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:91)
   at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)
   at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:847)
   at org.jboss.remoting.transport.socket.ServerThread.completeInvocation(ServerThread.java:681)
   at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:634)
   at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:459)
   at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:197)
Caused by: java.sql.BatchUpdateException: failed batch
   at org.hsqldb.jdbc.jdbcStatement.executeBatch(Unknown Source)
   at org.hsqldb.jdbc.jdbcPreparedStatement.executeBatch(Unknown Source)
   at org.jboss.resource.adapter.jdbc.CachedPreparedStatement.executeBatch(CachedPreparedStatement.java:476)
   at org.jboss.resource.adapter.jdbc.WrappedStatement.executeBatch(WrappedStatement.java:774)
   at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:244)
   ... 62 more


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 24, 2008 11:40 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

Looking at your SQL trace it seems you are doing more than just adding players to a team. It would help to see some more of the source code.

Also set hibernate.jdbc.batch_size=0, this will prevent batch updates and should result in better error messages.

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 25, 2008 9:54 am 
Newbie

Joined: Wed May 16, 2007 11:36 am
Posts: 3
HSQLDB doesn't seem to support batch updates, therefore setting hibernate.jdbc.batch_size to 0, as Hardy proposed, should fix that issue.

Had that issue in my own application and its also mentioned here: http://raibledesigns.com/wiki/Wiki.jsp? ... thHSQLDB-4


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.