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.  [ 22 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: Thu Jul 27, 2006 8:49 am 
Newbie

Joined: Wed Jul 26, 2006 6:01 am
Posts: 10
We have the same problem...

Code:
   private void addGroup2Group(){
      Integer parentgroupid = null;
      Integer childgroupid = null;
      BufferedReader d = new BufferedReader(new InputStreamReader(System.in));
      
      System.out.println("Wählen Sie eine Gruppe aus(Parent):");
      listGroups();
      
      try {
         parentgroupid = Integer.valueOf(d.readLine());
         System.out.println("Wählen Sie eine Gruppe aus(Child):");
         listGroups();
         childgroupid = Integer.valueOf(d.readLine());
      } catch (NumberFormatException e) {
         System.out.println("Nummer Eingeben!!!!");
         return;
      } catch (IOException e) {
         e.printStackTrace();
         return;
      }
      
      session = HibernateUtil.getSessionFactory().openSession();
      session.beginTransaction();
      
      PGroup child = (PGroup) session.load(PGroup.class, childgroupid);
      PGroup parent = (PGroup) session.load(PGroup.class, parentgroupid);
      
// With this line, the function works well !!!!
//      child.getName();
      
      if (parent == null){
         System.out.println("Es existiert keine Gruppe mit dieser ID:" + parentgroupid);
         return;
      }
      if (child == null){
         System.out.println("Es existiert keine Gruppe mit dieser ID:" + childgroupid);
         return;
      }
      
      parent.getElements().add(child);
      session.flush();
      session.getTransaction().commit();
      
      System.out.println("Gruppe : " + child.getName() + " wurde erfolgreich zu der Gruppe : " + parent.getName() + " hinzugefügt!");
      
      session.close();
   }



Error message:
Code:
27.07.2006 14:41:59 org.hibernate.AssertionFailure <init>
SCHWERWIEGEND: an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)
org.hibernate.AssertionFailure: collection [database.structure.PGroup.Elements] was not processed by flush()
   at org.hibernate.engine.CollectionEntry.postFlush(CollectionEntry.java:205)
   at org.hibernate.event.def.AbstractFlushingEventListener.postFlush(AbstractFlushingEventListener.java:332)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:28)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:993)
   at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:340)
   at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
   at logic.Hello.addGroup2Group(Hello.java:303)
   at logic.Hello.groupManager(Hello.java:241)
   at logic.Hello.groupManager(Hello.java:254)
   at logic.Hello.menu(Hello.java:31)
   at logic.Hello.main(Hello.java:385)


Has anybody an idea?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 27, 2006 5:12 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Still no idea, though your comment saying that accessing member property makes it work gave me a new lead to track down in the code. No joy though, I can't see any conditionals that might have caused a collection to be skipped during processing: the only escapes from that flow of control seem to be exceptions. And seeing as there's no other exceptions being reported, I'm at a loss.

joj46: As a matter of interest, if you access a member of the User entity before adding it to the Call, does the exception go away?
Code:
user = getUserByID();
user.getName(); // New line to force User entity to be processed.
call = new call();
call.setAgent(user);
makePersistent(call);
If it does, that would suggest a definite bug. We could search jira for this issue, it's bound to have come up before.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 28, 2006 2:31 am 
Newbie

Joined: Wed Jul 26, 2006 6:01 am
Posts: 10
HI,

I solved my problem as follows:

In order to add an Element to the "SET" we have to override 2 methods:
    equals()
    hashCode()


see: http://www.hibernate.org/hib_docs/v3/re ... lshashcode


now everything functions


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 28, 2006 1:49 pm 
Beginner
Beginner

Joined: Mon Jun 19, 2006 9:21 pm
Posts: 25
So I'm not sure which solution it was, but I first tried implementing the hash and the equals methods, but that didn't work. Then, when I added user.getUsername() it did. So I guess maybe you have to do both, make the hash and equals methods as well as actually getting whatever prop-ref your mapping refers to.
And tenwit, this has to be a bug. There is no conceivable reason why I should have to actually do a get on the property I'm refering to...at least I can't see a reason.

For those interested here's the little snippet of code that got it working for me

User user = DAOFactory.DEFAULT.getUserDAO().findById(this.getUserId());
user.getUsername();
call = new HomestudyCall();
call.setId(TokenGenerator.getUniqueID());
call.setAgent(user);

Pretty straight forward, but odd that I had to do that.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 28, 2006 1:57 pm 
Beginner
Beginner

Joined: Mon Jun 19, 2006 9:21 pm
Posts: 25
One more thing.....if you don't want to use a persistent class, but a transient one you can. Make sure you set the id of the transient class you are using. IE:
User user = new User();
user.setId(this.getUserId());
user.setUsername(this.getUserName());
user.getUsername();
call = new HomestudyCall();
call.setId(TokenGenerator.getUniqueID());
call.setAgent(user);

Tried it and it works....this was my original issue that ballooned into the new one.

I have a new question though (and I should probably start a new thread, but it's a fairly simple question...I think ). Whenever I insert a call using the above it does a select for the user when inserting the call. Is there a way to not have it do so...I know the user exists through other means, so I don't need hibernate to check that. I've noticed quite a few of my many-to-one do a select before inserting, but others, that have the same configuration, don't. Wasn't sure why that was happening, but I'd like to get it to stop that if I could. It's just more hits on the database that will end up causing me headaches later down the line when concurrent usage of the system gets larger.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 30, 2006 5:36 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
In that code snippet you don't need the user.getUsername(). If that's needed, it's only because it forces hibernate to load the entity; you're creating a transient entity, getUsername() isn't going to affect that.

Your question doesn't look too simple to me. You have unidirectional many-to-one associations in various places, and some mappings force a load of the one-end when inserting a new element on the many-end? But some mappings don't? Sounds very weird. You say you've just implemented hashCode() and equals(): perhaps you've done that wrong? There are a lot of rules about how to implement those methods, and if you do it wrong, there are a multitude of potential errors waiting for you.

Some rules for hashCode and equals methods in persitent classes:
  1. Don't refer to the DB id
  2. Don't refer to related objects, whether in a colleciton or a simple association
  3. Don't refer to often-changed properties like version numbers or timestamps

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject: this error occurs also:
PostPosted: Wed Apr 11, 2007 8:36 am 
Newbie

Joined: Mon Jan 23, 2006 10:06 am
Posts: 4
This error occurs also in special mapping conditions:
27.07.2006 14:41:59 org.hibernate.AssertionFailure <init>
SCHWERWIEGEND: an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)
org.hibernate.AssertionFailure: collection [database.structure.PGroup.Elements] was not processed by flush()
at org.hibernate.engine.CollectionEntry.postFlush(CollectionEntry.java:205)
at org.hibernate.event.def.AbstractFlushingEventListener.postFlush(AbstractFlushingEventListener.java:332)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:28)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:993)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:340)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)


mapping one:
User to paramValues:
Code:
<set name="paramValues" table="ParameterValue" inverse="true" cascade="all,delete-orphan" [b]lazy="false"[/b]>
         <key column="USER_FK_ID"/>
<one-to-many class="ParameterValue"/>
</set>

mapping two:
ParameterValue to user:
Code:
<many-to-one name="user" foreign-key="FK_PARAMVALUE_TO_USER">
<column name="USER_FK_ID" length="40"/>
</many-to-one>



if you load the paramvalues and the user over a criteria (which has the paramValues eager fetched) it will occur the error mentioned above.

I'm using ThreadLocal- and session-per-conversation Pattern

Best regards
Dominic


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 22 posts ]  Go to page Previous  1, 2

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.